# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1152948 | MinhTuan11 | Colors (BOI20_colors) | C++20 | 0 ms | 440 KiB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
const int N = 2e5 + 5;
const int K = 1e2 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 7;
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
using namespace std;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int n;
vector<int> m;
int ask(int ques) {
cout << "? " << ques << endl;
int rep;
cin >> rep;
return rep;
}
void prep() {
int l = 1, r = n;
while(l < r - 1) {
int mid = l + r >> 1;
m.push_back(mid);
l = mid;
}
}
void solve() {
int mini = 0, maxi = 0, cur = 0;
for(int i = 0; i < m.size(); i++) {
if(i & 1) cur -= m[i];
else cur += m[i];
mini = min(mini, cur);
maxi = max(maxi, cur);
}
// if(maxi + (- mini) > n) {
// assert(1 == 2);
// }
// else {
int pos = - mini + 1, query = 1;
int rep = ask(pos);
int l = 0, r = n, mid;
while(l < r - 1) {
mid = l + r >> 1;
if(query & 1) {
pos += mid;
}
else {
pos -= mid;
}
++query;
rep = ask(pos);
if(rep) r = mid;
else l = mid;
}
cout << "= " << r << endl;
// }
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if(ifstream("file.inp")){
freopen("file.inp", "r", stdin);
freopen("file.out", "w", stdout);
}
cin >> n;
prep();
solve();
return 0;
}
// tuntun
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |