Submission #763705

# Submission time Handle Problem Language Result Execution time Memory
763705 2023-06-22T16:27:02 Z aaron_dcoder Colors (BOI20_colors) C++17
0 / 100
0 ms 300 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

bool did_archie_notice(ll col) {
    int ans;
    cout << "? " << col << endl;
    cin >> ans;
    return (ans == 1);
}

int main() {
    ll N;
    cin >> N;
    set<ll> used_up;
    ll curren_hair_color = N/3 + 1;
    did_archie_notice(curren_hair_color);
    
    ll maximum_possible_value_C = N;
    ll minimum_possible_value_C = 1;

    ll next_direc = 1;

    while (maximum_possible_value_C!=minimum_possible_value_C) {
        //cout << "max pv:" << maximum_possible_value_C << ",min pv:" << minimum_possible_value_C << " ,haircol:" << curren_hair_color << "\n";
        ll to_check = (maximum_possible_value_C+minimum_possible_value_C)/2;
        ll oldhaircolor = curren_hair_color;
        bool hasnoticed;
        for (ll chk_disp = 0; chk_disp<N; chk_disp++) {
            ll next_check= curren_hair_color + next_direc*(to_check-chk_disp);
            if ((to_check-chk_disp) >= maximum_possible_value_C || (to_check-chk_disp) < minimum_possible_value_C) {
                throw exception();
            }
            if (used_up.count(next_check)==0) {
                used_up.insert(next_check);
                hasnoticed = did_archie_notice(next_check);
                curren_hair_color = next_check;
                break;
            }
            next_check= curren_hair_color + next_direc*(to_check+chk_disp);
            if ((to_check+chk_disp) >= maximum_possible_value_C || (to_check+chk_disp) < minimum_possible_value_C) {
                throw exception();
            }
            if (used_up.count(next_check)==0) {
                used_up.insert(next_check);
                hasnoticed = did_archie_notice(next_check);
                curren_hair_color = next_check;
                break;
            }
        }
        if (hasnoticed) {
            maximum_possible_value_C = abs(oldhaircolor-curren_hair_color);
        }
        else {
            minimum_possible_value_C = abs(oldhaircolor-curren_hair_color)+1;
        }
        next_direc *= -1;
    }

    cout << "= " << maximum_possible_value_C;
}
    

Compilation message

Colors.cpp: In function 'int main()':
Colors.cpp:52:9: warning: 'hasnoticed' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |         if (hasnoticed) {
      |         ^~
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 300 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 300 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 300 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 300 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 300 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -