# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1032951 |
2024-07-24T11:14:33 Z |
anango |
Worm Worries (BOI18_worm) |
C++17 |
|
3000 ms |
14828 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1LL<<30;
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 n,m,k,q;
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;
}
map<vector<int>,int> cache;
int query(int x, int y, int z) {
if (cache.count({x,y,z})) return cache[{x,y,z}];
cout << "? " << x <<" " << y <<" " <<z << endl;
qcount++;
if (qcount>=q-3) {
while (1==1) {
int o=0;
}
}
int an;
if (!debug) {
cin >> an;
}
else {
cout << humidity[x-1][y-1][z-1] << endl;
return cache[{x,y,z}] = humidity[x-1][y-1][z-1];
}
return cache[{x,y,z}] = 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)));
if (debug) {
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
for (int k1=0; k1<k; k1++) {
humidity[i][j][k1]=rng();
}
}
}
}
vector<vector<int>> points; //humidity,x,y,z
int q1 = q/3;
int q2 = q-q1;
int pathlength = q2/6;
for (int i=0; i<q1; i++) {
int x,y,z; x=rng()%n; y=rng()%m; z=rng()%k; x++; y++; z++;
points.push_back({query(x,y,z),x,y,z});
}
sort(points.begin(), points.end());
reverse(points.begin(), points.end());
int a,x,y,z;
a = points[0][0]; x = points[0][1]; y = points[0][2]; z = points[0][3];
while (1) {
bool changed = 0;
int ma=query(x,y,z);
for (vector<int> j:neighbours({x,y,z})) {
if (query(j[0],j[1],j[2])>ma) {
x = j[0]; y=j[1]; z=j[2]; changed=1; ma=query(j[0],j[1],j[2]);
}
}
if (!changed) break;
}
answer(x,y,z);
}
Compilation message
worm.cpp: In function 'long long int query(long long int, long long int, long long int)':
worm.cpp:35:17: warning: unused variable 'o' [-Wunused-variable]
35 | int o=0;
| ^
worm.cpp: In function 'int main()':
worm.cpp:87:9: warning: unused variable 'pathlength' [-Wunused-variable]
87 | int pathlength = q2/6;
| ^~~~~~~~~~
worm.cpp:94:9: warning: variable 'a' set but not used [-Wunused-but-set-variable]
94 | int a,x,y,z;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
856 KB |
Output is correct |
2 |
Correct |
21 ms |
852 KB |
Output is correct |
3 |
Correct |
22 ms |
860 KB |
Output is correct |
4 |
Correct |
27 ms |
856 KB |
Output is correct |
5 |
Correct |
22 ms |
1424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3047 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
6 ms |
656 KB |
Output is correct |
3 |
Correct |
10 ms |
856 KB |
Output is correct |
4 |
Correct |
7 ms |
636 KB |
Output is correct |
5 |
Correct |
9 ms |
824 KB |
Output is correct |
6 |
Correct |
9 ms |
600 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
600 KB |
Output is correct |
2 |
Correct |
9 ms |
608 KB |
Output is correct |
3 |
Correct |
8 ms |
468 KB |
Output is correct |
4 |
Correct |
13 ms |
600 KB |
Output is correct |
5 |
Correct |
7 ms |
600 KB |
Output is correct |
6 |
Correct |
6 ms |
532 KB |
Output is correct |
7 |
Correct |
9 ms |
600 KB |
Output is correct |
8 |
Execution timed out |
3066 ms |
1036 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
6996 KB |
Output is correct |
2 |
Correct |
216 ms |
7316 KB |
Output is correct |
3 |
Correct |
254 ms |
7248 KB |
Output is correct |
4 |
Correct |
303 ms |
7280 KB |
Output is correct |
5 |
Correct |
267 ms |
7296 KB |
Output is correct |
6 |
Correct |
248 ms |
7284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
395 ms |
9376 KB |
Output is correct |
2 |
Correct |
374 ms |
9500 KB |
Output is correct |
3 |
Correct |
407 ms |
9708 KB |
Output is correct |
4 |
Correct |
578 ms |
12060 KB |
Output is correct |
5 |
Correct |
448 ms |
11168 KB |
Output is correct |
6 |
Correct |
415 ms |
10336 KB |
Output is correct |
7 |
Correct |
788 ms |
14828 KB |
Output is correct |
8 |
Correct |
309 ms |
9796 KB |
Output is correct |
9 |
Correct |
459 ms |
11712 KB |
Output is correct |
10 |
Correct |
397 ms |
10404 KB |
Output is correct |
11 |
Correct |
480 ms |
11760 KB |
Output is correct |