Submission #1260087

#TimeUsernameProblemLanguageResultExecution timeMemory
1260087niepamietamhaslaWorm Worries (BOI18_worm)C++20
59 / 100
204 ms4076 KiB
#include <bits/stdc++.h> #define pii pair<int,int> using namespace std; typedef long long ll; 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 main(){ cin >> n >> m >> k >> q; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...