제출 #1338305

#제출 시각아이디문제언어결과실행 시간메모리
1338305lmaobruhWorm Worries (BOI18_worm)C++20
0 / 100
236 ms165728 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define ve vector
#define vi ve<int>
#define vii ve<ii>
#define vl ve<ll>
#define ar array
#define all(x) x.begin(), x.end()
#define fo(i,a,b) for (int i=(a); i<=(b); ++i)
#define fd(i,a,b) for (int i=(a); i>=(b); --i)
#define err(x) cerr << (#x) << " = " << (x) << '\n'
#define popcount(x) __builtin_popcountll(x)
#define siz(x) ((int)(x).size())
#define _ << ' ' <<
#define nl cout << '\n'
#define dbg(x...) [](auto...a){ ((cerr << a << ' '), ...) << endl;}(#x, ":", x)
template<class T> bool maxi(T &a, T b) { return (a < b ? a = b, 1 : 0); }
template<class T> bool mini(T &a, T b) { return (a > b ? a = b, 1 : 0); }
template<class T> ostream& operator<<(ostream &os, ve<T> v) {os << "{"; fo(i,0,siz(v)-1) { if(i) os << ", "; os << v[i]; } os << "}"; return os;}
template<class U, class V> ostream& operator<<(ostream &os, pair<U, V> p) {os << "(" << p.fi << ", " << p.se << ")";return os;}
const int N = 1e6+5, inf = 1e9+10, mod = 1e9+7;

mt19937 rng((ll)(new char));

int rand(int l, int r) {
    return rng()%(r-l+1)+l;
}

int n, m, k, q, memo[505][505][505], cnt;

int ask(int x, int y, int z) {
    if (x < 0 || x > n || y < 0 || y > m || z < 0 || z > k) return 0;
    if (memo[x][y][z]) return memo[x][y][z];
    q--; assert(q>=0);
    cout << "? " << x << ' ' << y << ' ' << z << endl;
    int val; cin >> val; return memo[x][y][z] = val;
}

const int dx[]={1,0,0,-1,0,0};
const int dy[]={0,1,0,0,-1,0};
const int dz[]={0,0,1,0,0,-1};

void sol() {
    cin >> n >> m >> k >> q;
    if (max({n,m,k}) <= 500) {
        int best=0;
        ar<int,3> pos;

        fo(i,1,q/2) {
            int x = rand(1, n), y = rand(1, m), z = rand(1, k);
            int cur = ask(x, y, z);
            if (maxi(best, cur)) pos={x,y,z};
        }

        while (1) {
            bool upd=0;
            fo(i,0,5) {
                int val = ask(pos[0]+dx[i], pos[1]+dy[i], pos[2]+dz[i]);
                if (maxi(best, val)) {
                    pos[0]+=dx[i], pos[1]+=dy[i], pos[2]+=dz[i];
                    upd=1;
                }
            }
            if (!upd) {
                assert(ask(pos[0], pos[1], pos[2]) == best);
                fo(i,0,5) {
                    assert(ask(pos[0]+dx[i], pos[1]+dy[i], pos[2]+dz[i]) <= best);
                }
                cout << "! " << pos[0] << ' ' << pos[1] << ' ' << pos[2] << endl;
                return;
            }
        }

        return;
    }
}

signed main(){
//    ios::sync_with_stdio(0); cin.tie(0);
//    if(fopen("A.inp","r")) {
//        freopen("A.inp","r",stdin);
//        freopen("A.out","w",stdout);
//    }
    int tc = 1; // cin >> tc;
    fo(i,1,tc) sol();
    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...