This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 gen(std :: chrono :: system_clock :: now().time_since_epoch().count());
int n, m, k, q;
namespace subtask2 {
const int N = 1010;
int H[N][N];
void run() {
auto ask = [&](int x, int y) {
if (x >= 1 && x <= n && y >= 1 && y <= n && H[x][y] == 0) {
cout << "? " << x << ' ' << y << ' ' << 1 << endl;
cin >> H[x][y];
}
return H[x][y];
};
int x = gen() % n + 1, y = gen() % m + 1;
while (1) {
tuple <int, int, int> best = {-1, 0, 0};
for (int a = x - 1; a <= x + 1; ++a)
for (int b = y - 1; b <= y + 1; ++b) {
if (a == x && b == y) continue;
best = max(best, {ask(a, b), a, b});
}
if (get<0>(best) <= ask(x, y)) {
cout << "! " << x << ' ' << y << ' ' << 1;
exit(0);
}
x = get<1>(best), y = get<2>(best);
}
}
}
namespace subtask3 {
const int N = 510;
int H[N][N][N];
void run() {
auto ask = [&](int x, int y, int z) {
if (x >= 1 && x <= n && y >= 1 && y <= n && z >= 1 && z <= n && H[x][y][z] == 0) {
cout << "? " << x << ' ' << y << ' ' << z << endl;
cin >> H[x][y][z];
}
return H[x][y][z];
};
int x = gen() % n + 1, y = gen() % m + 1, z = gen() % k + 1;
while (1) {
tuple <int, int, int, int> best = {-1, 0, 0, 0};
for (int a = x - 1; a <= x + 1; ++a)
for (int b = y - 1; b <= y + 1; ++b)
for (int c = z - 1; c <= z + 1; ++c) {
if (a == x && b == y && z == c) continue;
best = max(best, {ask(a, b, c), a, b, c});
}
if (get<0>(best) <= ask(x, y, z)) {
cout << "! " << x << ' ' << y << ' ' << z;
exit(0);
}
x = get<1>(best), y = get<2>(best), z = get<3>(best);
}
}
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k >> q;
if (k == 1) subtask2 :: run();
else subtask3 :: run();
}
# | 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... |