Submission #951131

#TimeUsernameProblemLanguageResultExecution timeMemory
951131koukirocksColors (BOI20_colors)C++17
22 / 100
1 ms596 KiB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
 
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;

int n;

int main() {
	speed;
	cin>>n;
	if (n<=64) {
		int now=1;
		int x;
		cout<<"? 1\n"<<flush;
		cin>>x;
		for (int i=1;i<n;i++) {
			now+=(i&1?1:-1)*(n-i);
			cout<<"? "<<now<<"\n"<<flush;
			cin>>x;
			if (x==0) {
				cout<<"= "<<(n-i+1)<<"\n"<<flush;
				return 0;
			}
		}
		cout<<"= 1\n"<<flush;
	} else if (n<=125) {
		int now=n+1>>1;
		int sml;
		cout<<"? "<<now<<"\n"<<flush;
		cin>>sml;
		cout<<"? 1\n"<<flush;
		cin>>sml;
		if (sml) {
			n=(n+1>>1)-1;
			now=1;
			for (int i=1;i<n;i++) {
				now+=(i&1?1:-1)*(n-i);
				int x;
				cout<<"? "<<now<<"\n"<<flush;
				cin>>x;
				if (x==0) {
					cout<<"= "<<(n-i+1)<<"\n"<<flush;
					return 0;
				}
			}
			cout<<"= 1\n"<<flush;
		} else {
			n=(n+1>>1)-1;
			now=1;
			for (int i=1;i<n;i++) {
				now+=(i&1?1:-1)*(2*n-i+1);
				int x;
				cout<<"? "<<now<<"\n"<<flush;
				cin>>x;
				if (x==0) {
					cout<<"= "<<(2*n-i+2)<<"\n"<<flush;
					return 0;
				}
			}
			cout<<"= "<<n+1<<"\n"<<flush;
		}
	} else if (n<=1000) {
		int k=sqrt(n); //1~k , k+1~2k , ... , k*k+1~n
		
		int now=1;
		int x;
		cout<<"? 1\n"<<flush;
		cin>>x;
//		cout<<k<<"\n";
		int gp=-1;
		for (int i=1;i<=k;i++) {
			now+=(i&1?1:-1)*(k-i+1);
			cout<<"? "<<min(now*k,n)<<"\n"<<flush;
			cin>>x;
			if (x==0) {
				gp=k-i+1;
				break;
			}
		}
		if (gp==-1) gp=0;
//		cout<<gp<<" gp\n"<<flush;
		now*=k;
		int dir=0;
		if (now>n/2) dir=1;
		// ans : gp*k+1 ~ (gp+1)*k
		for (int gap=min((gp+1)*k-1,n);gap>=gp*k+1;gap--) {
			if (dir) now-=gap;
			else now+=gap;
			dir^=1;
//		cout<<now<<" now2\n";
			cout<<"? "<<now<<"\n"<<flush;
			int x;
			cin>>x;
			if (x==0) {
				cout<<"= "<<gap+1<<"\n"<<flush;
				return 0;
			}
		}
		cout<<"= "<<gp*k+1<<"\n"<<flush;
	}
	return 0;
}

Compilation message (stderr)

Colors.cpp: In function 'int main()':
Colors.cpp:38:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   int now=n+1>>1;
      |           ~^~
Colors.cpp:45:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |    n=(n+1>>1)-1;
      |       ~^~
Colors.cpp:59:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |    n=(n+1>>1)-1;
      |       ~^~
#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...