Submission #580775

# Submission time Handle Problem Language Result Execution time Memory
580775 2022-06-21T19:02:48 Z Omar_Elgedawy Lost in the cycle (IOI19_cycle) C++14
0 / 100
0 ms 208 KB
#include <bits/stdc++.h>
//#include "grader.cpp"
 #include "cycle.h"
using namespace std;

void escape(int n) {
	if(jump(0)){
		int loc=0,one=0;
		int l=1,r=n-1;
		if(n%2==0&&jump(n/2)){
			return;
		}
		if(n%2==0){
			// cout<<n/2<<endl<<n/2+n%2<<endl;
			loc+=n/2;
			loc=(loc+n/2+n%2)%n;
			jump(n/2);
		}
		// cout<<loc<<endl;
		while(l<=r){
			int m=(r+l)/2;
			int dist;
			if(m>loc)
				dist=m-loc;
			else
				dist=((n-loc)+m)%n;
			loc=(loc+dist)%n;
			// cout<<loc<<' '<<dist<<' ';
			if(jump(dist)){
				r=m-1;
				one=loc;
			}
			else{
				l=m+1;
			}
		}
		if(loc<one){
			jump(one-loc);
			loc=(loc+(one-loc))%n;
		}
		else if(loc>one){
			jump(((n-loc)+one)%n);
			loc=(loc+(n-loc)+one)%n;
		}
		jump(n/2);
	}
	else{
		int loc=0,one;
		int l=1,r=n-1;
		while(l<=r){
			int m=(r+l)/2;
			int dist;
			if(m>loc)
				dist=m-loc;
			else
				dist=(n-loc)+m;
			loc=(loc+dist)%n;
			if(jump(dist)){
				r=m-1;
				one=loc;
			}
			else{
				l=m+1;
			}
		}
		if(loc<one)
			jump(one-loc);
		else if(loc>one)
			jump((n-loc)+one);
		jump(n/2);
	}
}

Compilation message

cycle.cpp: In function 'void escape(int)':
cycle.cpp:68:8: warning: 'one' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |   else if(loc>one)
      |        ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Incorrect 0 ms 208 KB The exit was not found.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 0 ms 208 KB The exit was not found.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Incorrect 0 ms 208 KB The exit was not found.
5 Halted 0 ms 0 KB -