답안 #580711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580711 2022-06-21T17:10:53 Z Omar_Elgedawy Lost in the cycle (IOI19_cycle) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "grader.cpp"
using namespace std;

void escape(int n) {
	if(jump(0)){
		int loc=0,one=0;
		int l=n/2,r=n-1;
		int lst=0;
		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;
			// cout<<l<<' '<<r<<' '<<m<<' '<<dist<<' '<<loc<<endl;
			if(jump(dist)){
				r=m-1;
				one=loc;
				lst=0;
			}
			else{
				lst=n-loc+1;
				l=m+1;
			}
		}
		// cout<<loc<<' '<<one;
		if(loc<one)
			jump(one-loc);
		else if(loc>one)
			jump((n-loc)+one);
		jump(n/2);
	}
	else{
		int loc=0,one;
		int l=1,r=n/2+1;
		int lst=0;
		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;
			// cout<<l<<' '<<r<<' '<<m<<' '<<dist<<' '<<loc<<endl;
			if(jump(dist)){
				r=m-1;
				one=loc;
				lst=0;
			}
			else{
				lst=n-loc+1;
				l=m+1;
			}
		}
		// cout<<loc<<' '<<one;
		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:9:7: warning: variable 'lst' set but not used [-Wunused-but-set-variable]
    9 |   int lst=0;
      |       ^~~
cycle.cpp:39:7: warning: variable 'lst' set but not used [-Wunused-but-set-variable]
   39 |   int lst=0;
      |       ^~~
cycle.cpp:62:8: warning: 'one' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |   else if(loc>one)
      |        ^~
/usr/bin/ld: /tmp/ccLB2Z5n.o: in function `jump(int)':
grader.cpp:(.text+0x0): multiple definition of `jump(int)'; /tmp/ccfSY6tr.o:cycle.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccLB2Z5n.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccfSY6tr.o:cycle.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status