이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define per(i, a, b) for (int i = b - 1; i >= a; --i)
#define trav(a, x) for (auto &a : x)
#define sz(a) a.size()
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
vector<vvi> grid;
int x, y, z, q;
int dx[] = {1, -1, 0, 0, 0, 0};
int dy[] = {0, 0, 1, -1, 0, 0};
int dz[] = {0, 0, 0, 0, 1, -1};
bool valid(int a, int b, int c) { return 0<=a && a < x && 0<=b && b < y && 0<=c && c < z; }
void question(int a, int b, int c) { cout << "? " << a + 1 << ' ' << b + 1 << ' ' << c + 1 << endl; }
bool check(int a, int b, int c) {
if (!grid[a][b][c]) {
question(a, b, c);
cin >> grid[a][b][c];
}
rep(i, 0, 9) {
int na = a + dx[i], nb = b + dy[i], nc = c + dz[i];
if (valid(na, nb, nc)) {
if (!grid[na][nb][nc]) {
question(na, nb, nc);
cin >> grid[na][nb][nc];
}
if (grid[a][b][c] < grid[na][nb][nc]) return 0;
}
}
return 1;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> x >> y >> z >> q;
grid=vector<vvi>(x,vvi(y,vi(z,0)));
if (y == 1 && z == 1) {
vi arr(x + 2, 0);
arr[0] = arr[x + 1] = 1;
int lo = 1, hi = x;
while (1) {
if (lo >= hi) {
cout << "! " << lo << " 1 1" << endl;
break;
}
int mid = (lo + hi) >> 1, n1, n2, n3;
if (arr[mid - 1])
n1 = arr[mid - 1];
else {
cout << "? " << mid - 1 << " 1 1" << endl;
cin >> n1;
arr[mid - 1] = n1;
}
if (arr[mid])
n2 = arr[mid];
else {
cout << "? " << mid << " 1 1" << endl;
cin >> n2;
arr[mid] = n2;
}
if (n2 < n1) {
hi = mid - 1;
continue;
}
if (arr[mid + 1])
n3 = arr[mid + 1];
else {
cout << "? " << mid + 1 << " 1 1" << endl;
cin >> n3;
arr[mid + 1] = n3;
}
if (n1 <= n2 && n3 <= n2) {
cout << "! " << mid << " 1 1" << endl;
break;
} else if (n2 < n3)
lo = mid + 1;
}
} else {
int a = (int) random() % x, b = (int) random() % y, c = (int) random() % z;
while (!check(a, b, c)) {
int mx = 0, na, nb, nc;
rep(l, 0, 9) {
int i = a + dx[l], j = b + dy[l], k = c + dz[l];
if (valid(i, j, k) && mx < grid[i][j][k]) {
mx = grid[i][j][k];
na = i, nb = j, nc = k;
}
}
a = na, b = nb, c = nc;
}
cout << "! " << a + 1 << ' ' << b + 1 << ' ' << c + 1 << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
worm.cpp: In function 'int main()':
worm.cpp:107:33: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
107 | int i = a + dx[l], j = b + dy[l], k = c + dz[l];
| ~~~~^
worm.cpp:3:40: note: within this loop
3 | #define rep(i, a, b) for (int i = a; i < b; ++i)
......
106 | rep(l, 0, 9) {
| ~~~~~~~
worm.cpp:106:13: note: in expansion of macro 'rep'
106 | rep(l, 0, 9) {
| ^~~
worm.cpp:115:61: warning: 'nc' may be used uninitialized in this function [-Wmaybe-uninitialized]
115 | cout << "! " << a + 1 << ' ' << b + 1 << ' ' << c + 1 << endl;
| ^
worm.cpp:115:50: warning: 'nb' may be used uninitialized in this function [-Wmaybe-uninitialized]
115 | cout << "! " << a + 1 << ' ' << b + 1 << ' ' << c + 1 << endl;
| ^~~
worm.cpp:115:34: warning: 'na' may be used uninitialized in this function [-Wmaybe-uninitialized]
115 | cout << "! " << a + 1 << ' ' << b + 1 << ' ' << c + 1 << endl;
| ^~~
# | 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... |