# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
319674 | seedkin | Hotter Colder (IOI10_hottercolder) | C11 | 673 ms | 9060 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "grader.h"
#include <stdio.h>
int HC(int N){
int g;
if (N == 1) return 1;
else if (N == 2) {
Guess(1);
g = Guess(2);
if(g == 1) return 2;
else return 1;
}
else if (N == 3) {
Guess(1);
g = Guess(3);
if(g == 1) return 3;
else if(g==-1) return 1;
else return 2;
}
int low = 1;
int high = N;
int flag = 1;
int p; // prev guess Num
int mid = (low+high) / 2;
Guess(mid - 1);
g = Guess(mid +1);
if(g == 0) return mid;
else if(g == 1) low = mid+1;
else high = mid+1;
p = mid + 1;
while ( high == N || low == 1 ) {
// printf("%d %d %d\n", low, high, N);
if(high == low) return low;
if( high - low < 3) {
if(low == 1) {
g = Guess(1);
if(g == 1) return 1;
else if ( g == -1) return high;
else return 2;
} else {
g = Guess(N);
if(g == 1) return N;
else if ( g == -1) return low;
else return N-1;
}
}
if(low == 1) {
g = Guess(low + (high - low) / 4);
if(g == 0) {
return (p + low +(high - low) / 4) >> 1;
} else if (g < 0 ) {
int temp = low;
low = ((p + low + (high - low) / 4) >> 1) + 1;
p = temp + (high - temp) / 4;
break;
}
g = Guess(low + (high - low) / 4 + 2);
if( g == 0 ) return low + (high - low) / 4 + 1;
else if ( g == -1) {
high = low + (high - low) / 4 + 2;
p = high;
continue;
} else {
low = low + (high - low) / 4 + 2;
p = low;
break;
}
} else {
g = Guess(high - (high - low) / 4);
if ( g == 0) {
return (p + high - (high - low) / 4) >> 1;
} else if (g < 0) {
int temp = high;
high = (p + high - (high - low) / 4 - 1) >> 1;
p = temp - (temp - low) / 4;
break;
}
g = Guess(high - (high - low) / 4 - 2);
if( g == 0 ) return high - (high - low) / 4 - 1;
else if ( g == -1) {
low = high - (high - low) / 4 - 2;
p = low;
continue;
} else {
high = high - (high - low) / 4 - 2;
p = high;
break;
}
}
}
while(high != low) {
int diff;
int target;
if(p <= low) {
diff = low - p;
target = high + diff;
} else if (p >= high) {
diff = p - high;
target = low - diff;
}
if( target < 1 ) {
Guess(high);
p = high;
continue;
}
if( target > N ) {
Guess(low);
p = low;
continue;
}
g = Guess(target);
if(g == 0) return (high+low) / 2;
if(g == 1 && target >= high) {
low = (low + high + 2) / 2;
} else if ( g == -1 && target >= high) {
high = (low + high - 1) / 2;
} else if ( g == 1 && target <= low) {
high = (low + high - 1) / 2;
} else if ( g == -1 && target <= low) {
low = (low + high + 2) / 2;
}
p = target;
}
return low;
// printf("%d %d\n", low, high);
// return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |