QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296914#5471. Interactive Number GuessingNaserTL 0ms0kbC++171.5kb2024-01-03 19:44:062024-01-03 19:44:06

Judging History

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

  • [2024-01-03 19:44:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-01-03 19:44:06]
  • 提交

answer

#include <bits/stdc++.h>
#include <unordered_map>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx,avx2")
#define int long long
#define endl '\n'
#define pii pair<int,int>
#define vint vector<int>
#define vpii vector<pii>
#define pb push_back
#define se second
#define fi first
#define all(x) x.begin(), x.end()
#define graph vector<vint>
using namespace std;
const int N = (int)1e5 + 69;
const int mod = (int)1e4 + 7;
const int naser = 3999, tourist = 3662;
int INF = INT_MAX;
int power(int a, int b) { int ans = 1; while (b) { if (b % 2) ans *= a; a *= a; b /= 2; } return ans; }
int gcd(int a, int b) { if (b == 0)return a;return gcd(b, a % b); }

int x = 999999999999999999;
int digsum(int xx) {
    int ans = 0;
    while (xx) {
        ans += xx % 10;
        xx /= 10;
    }
    return ans;
}
int query(int a) {
    cout << "query " << a << endl;
    int ans = digsum(x + a);
    cin >> ans;
    return ans;
}

int32_t main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    string ans = "answer ";
    int sum = query(0);
    for (int i = 0; i < 18; i++) {
        int dig = power(10, i),num = -1;
        int l = 0, r = 9;
        while (l <= r) {
            int mid = (l + r) / 2;
            int tmp = query(mid * dig);
            if (sum + mid == tmp)
                l = mid + 1, num = mid;
            else
                r = mid - 1;
        }
        ans.push_back('0' + 9 - num);
    }
    reverse(ans.begin() + 7, ans.end());
    cout << ans << endl;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:


output:


result: