QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#224121 | #5471. Interactive Number Guessing | DAleksa | TL | 0ms | 0kb | C++14 | 847b | 2023-10-22 23:59:59 | 2023-10-23 00:00:00 |
answer
#include <bits/stdc++.h>
using namespace std;
long long n;
int d(long long n) {
int res = 0;
while(n > 0) {
res += n % 10;
n /= 10;
}
return res;
}
int ask(long long x) {
return d(n + x);
cout << "query " << x << endl;
long long res;
cin >> res;
return res;
}
int main() {
cin >> n;
int sum = ask(0);
long long res = 0;
long long pw = 1;
for(int i = 0; i < 18; i++) {
int l = 1, r = 10;
int ans = r;
while(l <= r) {
int mid = (l + r) / 2;
if(ask(mid * 1LL * pw) != sum + mid) {
ans = mid;
r = mid - 1;
} else l = mid + 1;
}
res += pw * (10 - ans);
pw *= 10;
}
cout << "answer " << res;
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded