이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <stdlib.h>
#include <map>
int __query(int x, int y, int z) {
printf("? %d %d %d\n", x, y, z);
fflush(stdout);
int ans = -1;
static int t;
(void)scanf("%d", &ans);
if (ans == -1) exit(0);
return ans;
}
std::map<int, int> M;
int query(int x, int y, int z) {
int t = x | y << 10 | z << 20;
if (M.find(t) == M.end()) M[t] = __query(x, y, z);
return M[t];
}
__attribute__((noreturn))
void guess(int x, int y, int z) {
printf("! %d %d %d\n", x, y, z);
exit(0);
}
int main() {
int N, M, K, Q;
(void)scanf("%d %d %d %d", &N, &M, &K, &Q);
// TODO do something smart
if (M == 1) {
int L = 1, R = N;
while (L < R) {
if (R - L == 1) {
if (query(L, 1, 1) > query(R, 1, 1)) R = L;
else L = R;
continue;
}
int M1 = (L + L + R) / 3, M2 = (L + R + R + 2) / 3;
int q1 = query(M1, 1, 1), q2 = query(M2, 1, 1);
if (q1 > q2) {
if (q1 > query(M1 + 1, 1, 1)) R = M1;
else {
L = M1 + 1;
R = M2 - 1;
}
}
else {
if (q2 > query(M2 - 1, 1, 1)) L = M2;
else {
L = M1 + 1;
R = M2 - 1;
}
}
}
guess(L, 1, 1);
}
}
컴파일 시 표준 에러 (stderr) 메시지
worm.cpp: In function 'int __query(int, int, int)':
worm.cpp:9:13: warning: unused variable 't' [-Wunused-variable]
static int t;
^
worm.cpp:10:2: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
(void)scanf("%d", &ans);
^~~~~~~~~~~~~~~~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:31:2: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
(void)scanf("%d %d %d %d", &N, &M, &K, &Q);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
worm.cpp: At global scope:
worm.cpp:9:13: warning: 't' defined but not used [-Wunused-variable]
static int t;
^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |