Submission #945744

# Submission time Handle Problem Language Result Execution time Memory
945744 2024-03-14T07:17:05 Z yeediot Colors (BOI20_colors) C++14
0 / 100
1 ms 448 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
int c;
void init(int n){
    cin>>c;
}
int last;
bool query(int x){
    cout<<"? "<<x<<' ';
    if(abs(x-last)>=c){
        last=x;
        cout<<1<<'\n';
        return 1;
    }
    last=x;
    cout<<0<<'\n';
    return 0;
}
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void init(int n){}
bool query(int x){
    cout<<"? "<<x<<endl;
    cin>>x;
    return x;
}
void setio(){}
#define debug(x...)
#endif

signed main(){
    setio();
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    init(n);
    int st=(n+3)/2.0;
    int x=query(st);
    int l=1,r=n;
    int prev=st;
    bool flag=1;
    while(l<r){
        int mm=l+r>>1;
        //debug(prev-mm,prev+mm);
        /*if(prev-mm<1 and prev+mm>n){
            x=query(1);
            prev=1;
            continue;
        }
        else if(prev+mm<=n and (prev-mm<1 or n-prev-mm<prev-mm-1)){
            x=query(prev+mm);
            prev=prev+mm;
        }
        else{
            x=query(prev-mm);
            prev=prev-mm;
        }*/
        if(flag){
            x=query(prev-mm);
            flag=0;
            prev=prev-mm;
        }
        else{
            x=query(prev+mm);
            flag=1;
            prev=prev+mm;
        }
        if(x){
            r=mm;
        }
        else{
            l=mm+1;
        }
    }
    cout<<"= "<<l<<'\n';
}
 /*
 input:
 
 */















 

Compilation message

Colors.cpp: In function 'int main()':
Colors.cpp:77:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |         int mm=l+r>>1;
      |                ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -