답안 #1030723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030723 2024-07-22T09:08:36 Z ttamx Colors (BOI20_colors) C++17
0 / 100
0 ms 344 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

const int LG=59;
const ll LIM=1e18;
const bool AUTO=false;

ll n;
ll c;
ll pre=-1;

const ll SEED=time(nullptr);

mt19937_64 rng(SEED);

ll rnd(ll x){
    return rng()%x+1;
}

inline int ask(ll x){
    if(x<1||n<x){
        cerr << x << " is out of bound";
        assert(false);
    }
    if(AUTO){
        if(pre==-1){
            pre=x;
            return 0;
        }else{
            ll d=abs(pre-x);
            pre=x;
            return d>=c;
        }
    }
    cout << "? " << x << endl;
    int res;
    cin >> res;
    return res;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    do{
        if(AUTO){
            n=rnd(LIM);
            c=rnd(n);
            pre=-1;
            cerr << "n = " << n << ", " << "c = " << c << "\n";
        }else{
            cin >> n;
        }
        ll pos=1,dir=1,st=1,step=0;
        int cnt=0;
        for(ll i=n;i>1;i=(i+1)/2){
            step+=i/2;
            pos+=dir*step;
            if(pos<1){
                ll dif=1-pos;
                pos+=dif,st+=dif;
            }
            dir=-dir;
        }
        ll ans=1;
        ask(st);
        dir=1,step=0;
        for(ll i=n;i>1;i=(i+1)/2){
            st+=dir*(step+i/2);
            if(!ask(st)){
                ans+=i/2;
                step+=i/2;
            }
            dir=-dir;
        }
        cout << "= " << ans << endl;
        if(AUTO&&ans!=c){
            cerr << "expected " << c << " found " << ans << endl;
            assert(false);
        }
    }while(AUTO);
}

Compilation message

Colors.cpp: In function 'int main()':
Colors.cpp:56:13: warning: unused variable 'cnt' [-Wunused-variable]
   56 |         int cnt=0;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB OK (4 queries)
2 Correct 0 ms 344 KB OK (7 queries)
3 Correct 0 ms 344 KB OK (5 queries)
4 Correct 0 ms 344 KB OK (6 queries)
5 Incorrect 0 ms 344 KB Hair color 16 was used multiple times
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB OK (4 queries)
2 Correct 0 ms 344 KB OK (7 queries)
3 Correct 0 ms 344 KB OK (5 queries)
4 Correct 0 ms 344 KB OK (6 queries)
5 Incorrect 0 ms 344 KB Hair color 16 was used multiple times
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB OK (4 queries)
2 Correct 0 ms 344 KB OK (7 queries)
3 Correct 0 ms 344 KB OK (5 queries)
4 Correct 0 ms 344 KB OK (6 queries)
5 Incorrect 0 ms 344 KB Hair color 16 was used multiple times
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB OK (4 queries)
2 Correct 0 ms 344 KB OK (7 queries)
3 Correct 0 ms 344 KB OK (5 queries)
4 Correct 0 ms 344 KB OK (6 queries)
5 Incorrect 0 ms 344 KB Hair color 16 was used multiple times
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB OK (4 queries)
2 Correct 0 ms 344 KB OK (7 queries)
3 Correct 0 ms 344 KB OK (5 queries)
4 Correct 0 ms 344 KB OK (6 queries)
5 Incorrect 0 ms 344 KB Hair color 16 was used multiple times
6 Halted 0 ms 0 KB -