QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#224121#5471. Interactive Number GuessingDAleksaTL 0ms0kbC++14847b2023-10-22 23:59:592023-10-23 00:00:00

Judging History

你现在查看的是最新测评结果

  • [2023-10-23 00:00:00]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-22 23:59:59]
  • 提交

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

input:


output:


result: