Submission #1274447

#TimeUsernameProblemLanguageResultExecution timeMemory
1274447nickkumaMađioničar (COI22_madionicar)C++20
0 / 100
490 ms404 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define int long long int n; bool ask(int i, int sz){ int resp; cout << "? " << i << ' ' << i+sz-1 << '\n' << flush; cin >> resp; return resp==1; } void sol(){ cin >> n; //even sized palindromes int ans=0; bool found=0; int sz=2; do{ found=0; for(int i=1;i<=n-sz+1;i++){ if(ask(i,sz)){ found=1; ans=max(ans,sz); int l=i, r=i+sz-1; while(1<=l-1 && r+1<=n){ //expand palin l--; r++; if(ask(l,r-l+1))ans=max(ans,r-l+1); else break; } } } }while(found); //odd sized palindromes sz=3; do{ found=0; for(int i=1;i<=n-sz+1;i++){ if(ask(i,sz)){ found=1; ans=max(ans,sz); int l=i, r=i+sz-1; while(1<=l-1 && r+1<=n){ //expand palin l--; r++; if(ask(l,r-l+1))ans=max(ans,r-l+1); else break; } } } }while(found); cout << "! " << ans << '\n' << flush; cout.flush(); return; } signed main(){ int tc=1; // cin >> tc; while(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...