이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1LL<<30;
int n,m,k,q;
mt19937 rng;
vector<int> dx = {0,0,0,0,-1,1};
vector<int> dy = {0,0,-1,1,0,0};
vector<int> dz = {-1,1,0,0,0,0};
int qcount = 0;
int debug = 0;
vector<vector<vector<int>>> humidity;
vector<vector<int>> neighbours(vector<int> point) {
vector<vector<int>> ans;
for (int dir=0; dir<6; dir++) {
int nx,ny,nz; nx=point[0]+dx[dir]; ny=point[1]+dy[dir]; nz=point[2]+dz[dir];
if (!(1<=nx && nx<=n && 1<=ny && ny<=m && 1<=nz && nz<=k)) {
continue;
}
ans.push_back({nx,ny,nz});
}
return ans;
}
int query(int x, int y, int z) {
cout << "? " << x <<" " << y <<" " <<z << endl;
qcount++;
int an;
if (!debug) {
cin >> an;
}
else {
cout << humidity[x-1][y-1][z-1] << endl;
return humidity[x-1][y-1][z-1];
}
return an;
}
void answer(int x, int y, int z) {
cout << "! " << x << " " << y << " " << z << endl;
if (debug) {
cout << "in " << qcount <<" " << "queries" << endl;
int gg=0;
for (auto j:neighbours({x,y,z})) {
if (humidity[j[0]-1][j[1]-1][j[2]-1]>humidity[x-1][y-1][z-1]) {
gg=1;
}
}
if (gg) {
cout << "INCORRECT" << endl;
}
else {
cout << "CORRECT" << endl;
}
}
}
signed main() {
rng.discard((time(NULL))%100000);
cin >> n >> m >> k >> q;
if (debug) {
humidity = vector<vector<vector<int>>>(n,vector<vector<int>>(m,vector<int>(k,0)));
for (int i=0; i<n; i++) {
humidity[i][0][0] = 10000000-abs(88-(i+1));
}
}
int l = 1;
int r = n;
int known = (l+r)/2;
int knownval = query(known,1,1);
while (l<r-1) {
int m1,m2,m1v,m2v;
if ((known==(known+r)/2 || (rng()%2==0 && (known!=((l+known)/2))))) {
m1 = (l+known)/2; m1v = query(m1,1,1);
m2 = known; m2v = knownval;
}
else {
m1 = known; m1v = knownval;
m2 = (known+r)/2; m2v = query(m2,1,1);
}
if (debug) cout << "binary search " << l <<" " << m1 <<" " << m2 <<" " << r <<" " << m1v <<" " << m2v << endl;
if (m1v<m2v) {
l=m1+1;
r=r;
known = m2;
knownval = m2v;
}
else {
l=l;
r=m2-1;
known = m1;
knownval = m1v;
}
}
if (query(l,1,1)<query(r,1,1)) answer(r,1,1);
else answer(l,1,1);
}
# | 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... |