답안 #614160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
614160 2022-07-30T20:34:18 Z cadmiumsky Colors (BOI20_colors) C++14
0 / 100
0 ms 208 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

int last;
unordered_set<int> used;
bool query(int x) {
  cout << "? " << x + 1 << endl;
  used.insert(x);
  last = x;
  cin >> x;
  return x;
}

signed main() {
  int n;
  cin >> n;
  n--;
  vector<int> bits;
  int msk = 0;
  for(int i = 60; i >= 0; i--) {
    if((1LL << i) & n)
      bits.push_back(i),
      (bits.size() % 2 == 1? msk |= (1LL << i): 0);
  }
  //for(auto x : bits)
    //cerr << x << ' ';
  //cerr << '\n';
  int mine = 0, lelim = -1, toggle = 1;
  query(msk);
  for(int i = 0, x; i < bits.size(); i++) {
    x = bits[i];
    //cerr << toggle << '\n';
    if(toggle) {
      if(!query(last - mine - (1 << x)))
        mine += (1LL << x);
      else
        break;
    }
    else {
      if(!query((1LL << x) + mine + last))
        mine += (1LL << x);
      else
        break;
    }
    lelim = i;
    toggle ^= 1;
  }
  lelim++;
  assert(lelim != bits.size());
  lelim = bits[lelim] - 1;
  if(lelim >= 0) {
    bool unamog = 0;
    if(used.count(1LL << lelim))
      lelim--,
      unamog = 1;
    query((1LL << lelim));
    toggle = 0;
    lelim += unamog;
    for(int i = lelim; i >= 0; i--) {
      if(toggle == 0) {
        if(!query(last + (1LL << i) + mine))
          mine += (1LL << i);
      }
      else {
        if(!query(last - mine - (1LL << i)))
          mine += (1LL << i);
      }
      toggle ^= 1;
    }
  }
  cout << "= " << mine + 1 << endl;
  
}
// n = 24, C = 19

Compilation message

Colors.cpp: In function 'int main()':
Colors.cpp:32:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for(int i = 0, x; i < bits.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from Colors.cpp:1:
Colors.cpp:51:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   assert(lelim != bits.size());
      |          ~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Hair color 5 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Hair color 5 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Hair color 5 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Hair color 5 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Hair color 5 was used multiple times
2 Halted 0 ms 0 KB -