이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int query(int x, int y, int z) {
printf("? %d %d %d\n", x, y, z);
fflush(stdout);
int ans = -1;
(void)scanf("%d", &ans);
if (ans == -1) exit(0);
return ans;
}
__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);
assert(M == 1 && K == 1);
vector<int> cache(N+1);
auto ask = [&](int x) {
if (cache[x]) return cache[x];
return cache[x] = query(x, 1, 1);
};
if (N == 1) {
guess(1, 1, 1);
}
int l = 1, r = N;
int e1=-1, e2=-1;
if (ask(l) >= ask(l+1)) {
guess(l, 1, 1);
}
if (ask(r-1) <= ask(r)) {
guess(l, 1,1);
}
while (l < r-1) {
int m = (l+r) / 2;
int a = ask(m), b = ask(m+1);
if (a == b) {
e1 = m;
e2 = m+1;
}
if (a >= b) {
r = m;
} else {
l = m;
}
}
if (l != 1 && (ask(l-1) <= ask(l) && ask(l) >= ask(l+1)))
guess(l, 1, 1);
if (r != N && (ask(r-1) <= ask(r) && ask(r) >= ask(r+1)))
guess(r, 1, 1);
if (ask(e1-1) <= ask(e1) && ask(e1) >= ask(e2))
guess(e1, 1, 1);
else guess(e2, 1, 1);
}
컴파일 시 표준 에러 (stderr) 메시지
worm.cpp: In function 'int query(int, int, int)':
worm.cpp:8:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | (void)scanf("%d", &ans);
| ~~~~~^~~~~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:22:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | (void)scanf("%d %d %d %d", &N, &M, &K, &Q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |