1 solutions
-
0
Pascal :
program balance; var c,s:array[0..100000,0..50] of longint; pos:array[0..100000] of longint; t:array[0..100000] of string; n,tc,j,k,i,a,start,ans:longint; now:string; can:boolean; procedure change(k:longint); var now,tip:longint; begin now:=k; tip:=0; while now<>0 do begin inc(tip); c[i,tip]:=now mod 2; now:=now div 2; end; end; procedure qsort(a,b:longint); var i,j,temp1,y:longint; x,temp:string; begin i:=a; j:=b; x:=t[(a+b) div 2]; y:=pos[(a+b) div 2]; repeat while (t[i]<x) or ((t[i]=x) and (pos[i]<y)) do inc(i); while (t[j]>x) or ((t[j]=x) and (pos[j]>y)) do dec(j); if i<=j then begin temp:=t[i]; t[i]:=t[j]; t[j]:=temp; temp1:=pos[i]; pos[i]:=pos[j]; pos[j]:=temp1; inc(i); dec(j); end; until i>j; if i<b then qsort(i,b); if a<j then qsort(a,j); end; procedure deal(w:longint); var i,kk:longint; ch:string; begin for i:=1 to k do s[w,i]:=s[w-1,i]+c[w,i]; for i:=1 to k-1 do begin kk:=s[w,i+1]-s[w,i]; str(kk,ch); t[w]:=t[w]+ch; end; pos[w]:=w; end; begin //assign(input,'balance.in'); //assign(output,'balance.out'); //reset(input); //rewrite(output); readln(n,k); for i:=1 to n do begin readln(a); change(a); deal(i); end; for i:=1 to k-1 do t[0]:=t[0]+'0'; qsort(0,n); for i:=1 to n do begin can:=true; tc:=c[i,1]; for j:=2 to k do if c[i,j]<>tc then begin can:=false; break; end; if can then begin ans:=1; break; end; end; now:=t[0]; start:=pos[0]; for i:=1 to n do begin if t[i]<>now then begin if pos[i-1]-start>ans then ans:=pos[i-1]-start; start:=pos[i]; now:=t[i]; end; end; if pos[i]-start>ans then ans:=i-start; writeln(ans); //close(input); //close(output); end.
- 1
Information
- ID
- 543
- Time
- 2000ms
- Memory
- 256MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By