ok, found it out ;) Edited by author 13.05.2009 23:27 Hey, Can anyone tell me what is test 28?? I have time limit exceeded? This is my code: program Monobilliards_1494; var tmp, b, a, i, n: LongInt; x: array [1..100000] of LongInt; cheater: boolean; begin cheater := false; readln(n); for i := 1 to n do readln(x[i]); i := 1; tmp := x[1] - 1; while (i <= n) and not cheater do begin if tmp < x[i] then begin b := x[i] - i; tmp := x[i]; a := i + 1; while (a <= n) and (b > 0) do begin if tmp > x[a] then begin b := b - 1; tmp := x[a]; end; a := a + 1; end; end; tmp := x[i]; if b > 0 then cheater := true; i := i + 1; end; if cheater then writeln('Cheater') else writeln('Not a proof'); end. I don't know what is the problem mean, who can help me? I know AC solution to this problem, that uses O(1) memory. It is wrong, and answers "Not a proof" for test 4 3 1 4 2 I think that there is no correct solution with memory complexity less than O(N). N or at least N/2 integers may be required to be stored at some moment on hard test. On page http://acm.timus.ru/rating.aspx?space=1&num=1494&count=100there are many solutions that use too little memory to be correct. Your test and some others were added. 50 authors lost AC. By the way, it is possible to store N bools to solve this problem, and AC solutions with memory about 200K are OK. Edited by author 20.11.2008 13:52 By the way, it is possible to store N bools to solve this problem, and AC solutions with memory about 200K are OK. Is it _really_ possible to solve this problem using only N _booleans_? I mean it seems good enough to keep all necessary information, but not enough to search the information _fast_, so solutions with N booleans should probably get TL on a good test. Could you send such solution to e-mail, associated with my account? Test generated by the following program may be hard for some solutions storing only booleans. const n = 100000; var low, high : integer; begin assert(n mod 3 = 1); low := n div 3 + 1; high := low + 2; writeln(n); writeln(low); low := low - 1; while low > 0 do begin writeln(high); writeln(high - 1); high := high + 2; writeln(low); low := low - 1; end; end. Edited by author 22.11.2008 01:05 I can imagine a correct solution using N bits packed in integers. It uses O(N^2) time but with very good constant. But I think that solution using N booleans cannot pass TL. And you are right! Thank you. I added your test and some other tests of similar structure, and 85 authors got TL and WA. My algo is O(n). Reading and checking in one loop. With out stack, queue, array or recursion. It is really? Sorry, I don't speak English. #include<iostream> using namespace std; int array[100000]; int main() { long n; long number,lastnumber=0; cin>>n; long flag=0; for(int j=0;j<100000;j++) array[j]==0; for(long i=0;i<n;i++) { cin>>number; if(array[number-1]==1) { cout<<"Cheater"; return 0; } array[number-1]=1; if(lastnumber) if(!flag) { if(number<=lastnumber) flag=1; } else if(flag) if(number>=lastnumber) { cout<<"Cheater"; return 0; } lastnumber=number;
} cout<<"Not a proof"; return 0; } Test it with these data: 6 3 4 2 1 5 6 Answer is "Not a proof" P.S. Please DO NOT put your code, you can explain your algo. What do you mean by "ALMOST O(n)"? I mean that I have a loop to read data. It is O(n). But in it I have a loop for checking. In most cases it is about some iterations, but there are some tests that make my algo O(n^2). How to make it faster? I think that next sketch is O(N) Let x[1]...x[N]- revisor sequence k- Current number of an element of x under consideration NN- number of balls in billiard pocket now +last ball x[k] xx[]- aray of balls now in billiard pocket for moment k + last ball x[k] S-number of operations //Begining k=1 ;NN=x[1]; xx[]=[1..NN];//array assignment- x[1]- operations S:=x[1]; // Loop aa: j:=0; while (x[k+j]==xx[NN-j]) j++ //revisor takes seguental balls //from Billiard pocket;S:=S+j; k=k+j- next position if (k==N+1) "«Not a proof». END NN=NN-j; //number of balls in pocket after Session of taking; S:=S+1; m1=xx[k1]- next ball after timeout If (m1<=m) -"Cheater"//meet number smallet than taken xx[NN+1..NN+m1-m]:=[m+1..m1];// new sequence in billiard pocket //under ptevious rest S+=m1-m operations NN:=NN+m1-m;//renew S=S+1; goto aa //Loop The resume: S<=2*N -- O(N) I have such algo: a[0..100000]. a[i] means minimal number that can be taken after i not to be a cheater. during reading datas i have to cerrect the massive. but there are some tests that I must correct more than one element. I takes me a loop. So, TLE. P. S. I don't understand your algo ) Can you mail me "_magistr.90@mail.ru" ? We can speak Russian (or Ukrainian ;) ) It's just a stack modelling. You should suppose player not to be a cheater. Then he just puts balls into the pocket one by one: 1, 2, 3... until the last ball is the next ball to be checked. So, this ball should be removed. And so on. When the process is finished just check if the pocket is empty. Yes! And in my algoritnm xx[]- stac; NN- it's capacity; ANW, TLE#14 ((( For everyone who has TLE, use priority_queue. It is probably not the best solution, but it takes up only few lines. can you give me link where I can find algo or code for priority_queue? to svr: I don't know 2 things in you algoritm: ->m1=xx[k1]- next ball after timeout What is k1? ->If (m1<=m) -"Cheater"//meet number smallet than taken What is m? Please help me O(N^2) works! Time - 0.984 seconds))) Edited by author 21.03.2008 19:29 program zad2; var s,t,i,n,k:longint; x:array[1..100] of integer; begin readln(n); for i:=1 to n do readln(x[i]); s:=0; for i:=1 to n do if x[i]=i then inc(s); t:=0; for i:=n downto 1 do begin inc(k); if x[i]=k then inc(t); end; if (s=n) or (t=n) then writeln(' Not a proof ') else writeln(' Cheater '); end. Why dont proograme work ? ? ? What right answer for an example: 5 4 5 3 2 1 Not a cheater, obviously. why? Cuz, he can put 1 2 3 4 , then inspector can remove 4, he puts 5 and inspector removes 5 and there are balls 3 2 1 left in that order. Can somebody gives me some tests Help please! Here is my code #include <iostream> using namespace std; long a[100000]; long b[100000]; long c[100000]; int main() { long n,k=1,s,s1,l;
cin>>n; if(n==2) { cout<<"Not a proof"; goto tu; } for(int i=n;i>0;i--) { cin>>a[i]; }
while(a[k]<a[k+1]) { b[k]=a[k]; l=k; k++; } if(n-k==0) { cout<<"Not a proof"; goto tu; }
for(int i=k;i<=n;i++) { c[i]=a[i]; } n-=k; for(int i=k;i<=n;i++) { if(c[i]>=c[i+1]) { cout<<"Cheater"; goto tu; }} cout<<"Not a proof"; tu: ; system("pause"); return 0; } Edited by author 05.05.2008 02:57 And this my other solution #include <iostream> using namespace std; long a[1000000]; long u[1000000]; int main() { long n,b=0; cin>>n; int s=0,br=0,s1=0,x=1;
for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=n;i>0;i--) { b=a[i]; u[x]=b; x++; } for(int i=1;i<=n;i++) { s1=u[i+1]-u[i]; if((u[i]<u[i+1]) && (s1>1))br++; } for(int i=1;i<=n;i++) {s=u[i+1]-u[i]; if(s>1) { if(s==a[br]) br--; else {cout<<"Cheater"; goto tu; } if(s<0 && br==0) {cout<<"Cheater"; goto tu; } } } cout<<"Not a proof";
tu :; system("pause"); return 0; } Edited by author 05.05.2008 03:00 Does anybody know what's the problem? I will be very thankful if you will help me. Hic.. help me, i have some problem on test #6... :-/ Plz, help me! Give me some tests. sorry. now AC Edited by author 15.10.2006 18:54 |
|