ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1510. Order

It's Impossible
Posted by [TDUweAI] daminus 27 Jun 2013 13:45
here is my code. In my computer he got AC on test#1. But in timus that got WA#1

var
 a:array[0..500010] of longint;

procedure sort(l,r:longint);
var
 i,j,p,x:longint;
begin randomize;
 i:=l; j:=r; x:=a[random(r-l+1)+l];
 repeat
  while x>a[i] do inc(i);
  while x<a[j] do dec(j);
  if i<=j then
   begin
    p:=a[i];a[i]:=a[j];a[j]:=p;
    inc(i); dec(j);
   end;
 until i>j;
 if i<r then sort(i,r);
 if l<j then sort(l,j);
end;

var
 p,j,k,n,i,temp,have:longint;
begin
 readln(n);
 for i:=1 to n do
  readln(a[i]);
 sort(1,n);
 temp:=-1;
 for i:=1 to n do
  begin
   if a[i]=temp then begin inc(have); continue; end;
   if n mod 2=1 then k:=1 else k:=0;
   if have>=n div 2+k then begin writeln(temp); halt; end;
   have:=1;temp:=a[i];
  end;
 if n=1 then writeln(temp);
end.