Submission #1259999

#TimeUsernameProblemLanguageResultExecution timeMemory
1259999Szymon_PilipczukWorm Worries (BOI18_worm)C++20
10 / 100
8 ms416 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define st first #define nd second #define pb push_back #define all(a) a.begin(),a.end() #define rep(a,b) for(int a = 0;a<b;a++) const int inf = 1e9; const ll infl = 1e18; int main() { int n,m,k,q; cin>>n>>m>>k>>q; pair<pair<int,int>,pair<int,int>> bb; bb = {{1,n},{1,m}}; pair<int,pair<int,int>> tmx = {-1,{-1,-1}}; while(bb.st.st != bb.st.nd || bb.nd.st != bb.nd.nd) { if(bb.st.nd - bb.st.st > bb.nd.nd - bb.nd.st) { int mid = (bb.st.st+bb.st.nd)/2; pair<int,int> mx = {-1,-1}; for(int i = bb.nd.st;i <= bb.nd.nd;i++) { cout<<"?"<<" "<<mid<<" "<<i<<" "<<1<<endl; int c; cin>>c; if(mx.st < c) { mx.st = c; mx.nd = i; } if(tmx.st < c) { tmx.st = c; tmx.nd.st = mid; tmx.nd.nd = i; } } int m1 = -1,m2 = -1; if(mid != 1) { cout<<"? "<<mid-1<<" "<<mx.nd<<" "<<1<<endl; cin>>m1; if(tmx.st < m1) { tmx.st = m1; tmx.nd.st = mid-1; tmx.nd.nd = mx.nd; } } if(mid != n) { cout<<"? "<<mid+1<<" "<<mx.nd<<" "<<1<<endl; cin>>m2; if(tmx.st < m2) { tmx.st = m2; tmx.nd.st = mid+1; tmx.nd.nd = mx.nd; } } if(mx.st > m1 && mx.st > m2) { cout<<"! "<<mid<<" "<<mx.nd<<" "<<1<<endl; return 0; } if(tmx.nd.st > mid) { bb.st.st = mid + 1; } else { bb.st.nd = mid - 1; } } else { int mid = (bb.nd.st+bb.nd.nd)/2; pair<int,int> mx = {-1,-1}; for(int i = bb.st.st;i <= bb.st.nd;i++) { cout<<"?"<<" "<<i<<" "<<mid<<" "<<1<<endl; int c; cin>>c; if(mx.st < c) { mx.st = c; mx.nd = i; } if(tmx.st < c) { tmx.st = c; tmx.nd.st = i; tmx.nd.nd = mid; } } int m1 = -1,m2 = -1; if(mid != 1) { cout<<"? "<<mx.nd<<" "<<mid-1<<" "<<1<<endl; cin>>m1; if(tmx.st < m1) { tmx.st = m1; tmx.nd.st = mx.nd; tmx.nd.nd = mid-1; } } if(mid != n) { cout<<"? "<<mx.nd<<" "<<mid+1<<" "<<1<<endl; cin>>m2; if(tmx.st < m2) { tmx.st = m2; tmx.nd.st = mx.nd; tmx.nd.nd = mid+1; } } if(mx.st > m1 && mx.st > m2) { cout<<"! "<<mx.nd<<" "<<mid<<" "<<1<<endl; return 0; } if(tmx.nd.nd > mid) { bb.nd.st = mid + 1; } else { bb.nd.nd = mid - 1; } } } cout<<"! "<<bb.st.st<<" "<<bb.nd.st<<" "<<1<<endl; }
#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...