이 제출은 이전 버전의 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);
}
const double p = 0.381966;
int px[6] = { 1, -1, 0, 0, 0, 0 };
int py[6] = { 0, 0, 1, -1, 0, 0 };
int pz[6] = { 0, 0, 0, 0, 1, -1 };
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;
int T = L * p + R * (1 - p) + .5;
while (L < R) {
if (T + T == L + R) T = L * (1 - p) + R * p + .236;
int T2 = L + R - T;
if (T > T2) {
int T3 = T;
T = T2;
T2 = T3;
}
if (query(T, 1, 1) > query(T2, 1, 1)) R = T2 - 1;
else {
L = T + 1;
T = T2;
}
}
guess(L, 1, 1);
}
if (Q == 3500) {
int i, M, T, L = 1, R = N, D = 1, U = M;
while (L < R || D < U) {
if (R - L > U - D) {
M = L + R >> 1;
T = -1;
for (i = D; i <= U; i++) if (query(M, i, 1) > T) T = query(M, i, 1);
for (i = D; i <= U; i++) if (query(M + 1, i, 1) > T) break;
if (i > U) R = M;
else L = M + 1;
}
else {
M = D + U >> 1;
T = -1;
for (i = L; i <= R; i++) if (query(i, M, 1) > T) T = query(i, M, 1);
for (i = L; i <= R; i++) if (query(i, M + 1, 1) > T) break;
if (i > R) U = M;
else D = M + 1;
}
}
guess(L, D, 1);
}
int i, x, y, z, w = -1;
for (i = 0; i < Q / 5; i++) {
int tx = rand() % N + 1;
int ty = rand() % M + 1;
int tz = rand() % K + 1;
if (query(tx, ty, tz) > w) {
w = query(tx, ty, tz);
x = tx;
y = ty;
z = tz;
}
}
do {
for (i = 0; i < 6; i++) {
int tx = x + px[i], ty = y + py[i], tz = z + pz[i];
if (tx > 0 && tx <= N && ty > 0 && ty <= M && tz > 0 && tz <= K && query(tx, ty, tz) > query(x, y, z)) {
x = tx;
y = ty;
z = tz;
break;
}
}
} while (i == 6);
guess(x, y, z);
}
컴파일 시 표준 에러 (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: In function 'int main()':
worm.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
M = L + R >> 1;
~~^~~
worm.cpp:70:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
M = D + U >> 1;
~~^~~
worm.cpp: In function 'int __query(int, int, int)':
worm.cpp:10:3: 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:36: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;
^
worm.cpp: In function 'int main()':
worm.cpp:94:43: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
int tx = x + px[i], ty = y + py[i], tz = z + pz[i];
^~
worm.cpp:94:27: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
int tx = x + px[i], ty = y + py[i], tz = z + pz[i];
^~
worm.cpp:94:11: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
int tx = x + px[i], ty = y + py[i], tz = z + pz[i];
^~
worm.cpp:59:39: warning: 'M' may be used uninitialized in this function [-Wmaybe-uninitialized]
int i, M, T, L = 1, R = N, D = 1, U = M;
^
# | 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... |