제출 #680651

#제출 시각아이디문제언어결과실행 시간메모리
680651Cross_RatioWorm Worries (BOI18_worm)C++14
81 / 100
884 ms5704 KiB
#include <bits/stdc++.h> using namespace std; map<array<int, 3>, int> Ma; int N, M, K; int query_cnt = 0; int query(int a, int b, int c) { if(!(1<=a&&a<=N&&1<=b&&b<=M&&1<=c&&c<=K)) return -1; if(Ma.count({a, b, c})) return Ma[{a, b, c}]; query_cnt++; cout << "? " << a << ' ' << b << ' ' << c << endl; int d; cin >> d; Ma[{a, b, c}] = d; return d; } void answer(int a, int b, int c) { cout << "! " << a << ' ' << b << ' ' << c << endl; return; } int fibo[44]; void subtask_12() { int s = 1, e = fibo[30]+1; int x = fibo[28]+1, y = fibo[29]+1; while(s<=e) { if(s==e) { answer(s, 1, 1); return; } if(s+1==e) { if(query(s, 1, 1) >= query(e, 1, 1)) { answer(s, 1, 1); return; } else { answer(e, 1, 1); return; } } if(s+100>=e) { int mid = (s + e) / 2; if(query(mid, 1, 1) < query(mid+1, 1, 1)) { s = mid + 1; } else { e = mid; } continue; } if(query(x, 1, 1) >= query(y, 1, 1)) { e = y; y = x; x = (s+e) - y; } else { s = x; x = y; y = (s+e) - x; } } } void subtask_34() { int sx = 1, ex = N, sy = 1, ey = M; int rev = 0; int i, j; while(true) { if(sx==ex&&sy==ey) { assert(query(sx, sy, 1) >= query(sx-1, sy, 1)); assert(query(sx, sy, 1) >= query(sx+1, sy, 1)); assert(query(sx, sy, 1) >= query(sx, sy+1, 1)); assert(query(sx, sy, 1) >= query(sx, sy-1, 1)); answer(sx, sy, 1); return; } /*if(sx==ex&&sy+1==ey) { if(query(sx, sy, 1) >= query(sx, ey, 1)) { answer(sx, sy, 1); return; } else { answer(sx, ey, 1); return; } } if(sx+1==ex&&sy==ey) { if(query(sx, sy, 1) >= query(ex, sy, 1)) { answer(sx, sy, 1); return; } else { answer(ex, sy, 1); return; } }*/ if(rev) { if(sx<ex) { int mid = (sx+ex)/2; int ma = -1, ix = -1; for(i=sy;i<=ey;i++) { for(int j = mid; j <= mid+1; j++) { if(ma < query(j, i, 1)) { ma = query(j, i, 1); ix = j; } } } assert(ix!=-1); if(ix==mid) ex = mid; else sx = mid + 1; } } else { if(sy<ey) { int mid = (sy+ey)/2; int ma = -1, iy = -1; for(i=sx;i<=ex;i++) { for(int j = mid; j <= mid+1; j++) { if(ma < query(i, j, 1)) { ma = query(i, j, 1); iy = j; } } } assert(iy!=-1); if(iy==mid) ey = mid; else sy = mid + 1; } } rev = 1 - rev; } } void subtask_56() { } int dx[6] = {0, 0, 1, -1, 0, 0}; int dy[6] = {1, -1, 0, 0, 0, 0}; int dz[6] = {0, 0, 0, 0, 1, -1}; void subtask_naive() { int ma = -1, ix = -1, iy = -1, iz = -1; int loop = (K==1?1000:10000); while(loop--) { int x = rand() % N + 1, y = rand() % M + 1, z = rand() % K + 1; if(loop%100==1) { x = loop, y = loop; if(K!=1) z=loop; } if(ma < query(x, y, z)) { ma = query(x, y, z); ix = x, iy = y, iz = z; } } int x = ix, y = iy, z = iz; int lim = (K==1?4:6); while(true) { int val = query(x, y, z); bool isPos = true; for(int i=0;i<lim;i++) { if(val < query(x+dx[i], y+dy[i], z+dz[i])) { x += dx[i], y += dy[i], z += dz[i]; isPos = false; break; } } if(isPos) { answer(x, y, z); return; } } } signed main() { fibo[0] = fibo[1] = 1; int fibosum = 0; for(int i = 2 ; i <= 43; i++) { fibo[i] = fibo[i-1] + fibo[i-2]; //cout << i << " : " << fibo[i] << '\n'; } for(int i = 0; i <= 15; i++) fibosum += fibo[i]; //cout << fibosum*4 << '\n'; int Q; cin >> N >> M >> K >> Q; if(M==1 && K == 1) { subtask_12(); } else if(K==1 && N==M) { subtask_naive(); } else if(K==N && K==M) { subtask_naive(); } //cout << query_cnt; }

컴파일 시 표준 에러 (stderr) 메시지

worm.cpp: In function 'void subtask_34()':
worm.cpp:65:12: warning: unused variable 'j' [-Wunused-variable]
   65 |     int i, j;
      |            ^
#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...