제출 #580777

#제출 시각아이디문제언어결과실행 시간메모리
580777Omar_ElgedawyLost in the cycle (IOI19_cycle)C++14
100 / 100
1 ms208 KiB
#include <bits/stdc++.h>
//#include "grader.cpp"
 #include "cycle.h"
using namespace std;

void escape(int n) {
	if(n==3){
		if(jump(0)){
			jump(1);
		}
		else jump(2);
		return;
	}
	if(jump(0)){
		int loc=0,one=0;
		int l=n/2-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/2;
		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);
	}
}

컴파일 시 표준 에러 (stderr) 메시지

cycle.cpp: In function 'void escape(int)':
cycle.cpp:76:8: warning: 'one' may be used uninitialized in this function [-Wmaybe-uninitialized]
   76 |    jump((n-loc)+one);
      |    ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...