#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m, k, q;
map<ll, int> pamiec;
vector<pair<int,pii>> roza = {{0,{0,1}},{0,{0,-1}},{0,{1,0}},{0,{-1,0}},{1,{0,0}},{-1,{0,0}}};
int pars(int x, int y, int z){
if(x < 1 or x > n or y < 1 or y > m or z < 1 or z > k) return 0;
ll G = x - 1 + (y-1) * n + (z-1) *n*m;
if(pamiec.find(G) != pamiec.end()) return pamiec[G];
cout << "? " << x << " " << y << " " << z << "\n";
cin >> pamiec[G];
return pamiec[G];
}
pair<int, pii> synowie(int x, int y, int z){
int curr = pars(x, y, z);
for(auto u : roza){
int x2 = x + u.first;
int y2 = y + u.second.first;
int z2 = z + u.second.second;
if(pars(x2,y2,z2) > curr) return {x2, {y2,z2}};
}
return {-1, {-1, -1}};
}
int znajdz1d(ld a, ld b, pii znane){
if(a > b) return -1;
if(a == b) return a;
if(b - a + 1 <= 5){
for(int i = a; i <= b; ++i){
int lewo = pars(i-1, 1, 1);
int curr = pars(i, 1, 1);
int prawo = pars(i+1, 1, 1);
if(curr >= lewo and curr >= prawo){
return i;
}
}
}
pii split = znane;
if(split.first == -1){
split.first = (0.618 * a + 0.382 * b);
}
if(split.second == -1){
split.second = ((ld)0.382 * (ld)a + (ld)0.618 * (ld)b);
}
int L1 = pars(split.first, 1, 1);
int L2 = pars(split.second, 1, 1);
if(L1 >= L2){
return znajdz1d(a, split.second - 1, {-1, split.first});
}
else{
return znajdz1d(split.first + 1, b, {split.second, -1});
}
}
int main(){
cin >> n >> m >> k >> q;
if(m == 1 and k == 1 and q <= 35){
int x = znajdz1d(1, n, {-1, -1});
cout << "! " << x << " " << 1 << " " << 1 << "\n";
}
else if(k == 1 and q <= 3500){
}
else{
srand(time(NULL));
pair<int,pair<int,pii>> naj = {-1, {-1, {-1, -1}}};
for(int i = 0; i < q/3; ++i){
int x = rand() % n + 1;
int y = rand() % m + 1;
int z = rand() % k + 1;
naj = max(naj, {pars(x,y,z), {x, {y, z}}});
}
int x = naj.second.first;
int y = naj.second.second.first;
int z = naj.second.second.second;
while(true){
pair<int,pii> nxt = synowie(x, y, z);
if(nxt.first == -1) break;
x = nxt.first;
y = nxt.second.first;
z = nxt.second.second;
}
cout << "! " << x << " " << y << " " << z << "\n";
}
return 0;
}
# | 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... |