QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#224007 | #5471. Interactive Number Guessing | urosk | TL | 0ms | 0kb | C++14 | 1.6kb | 2023-10-22 22:54:36 | 2023-10-22 22:54:37 |
answer
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define ld double
#define ll unsigned long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define eb emplace_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define si(a) (ll)(a.size())
using namespace std;
ll n;
bool test = 1;
ll f(ll x){
ll ans = 0;
while(x){
ans+=x%10;
x/=10;
}
return ans;
}
map<ll,ll> mp;
ll cnt = 0;
ll ask(ll x){
cout<<"query "<<x<<endl;
if(mp.count(x)) return mp[x];
cnt++;
if(test) return f(n+x);
ll ans; cin >> ans;
return mp[x] = ans;
}
void tc(){
if(test) cin >> n;
ll c = 1;
ll poc = ask(0);
ll ans = 0;
for(ll d = 1;d<=17;d++){
ll l = 1,r = 9,mid,rez = 0;
while(l<=r){
mid = (l+r)/2;
if(ask(mid*c)==mid+poc){
rez = mid;
l = mid+1;
}else r = mid-1;
}
//dbg(rez);
ans+=(9-rez)*c;
c*=10;
//dbg(ans);
}
ans+=c*(poc-f(ans));
dbg(cnt);
cout<<"answer "<<ans<<endl;
}
int main(){
int t; t = 1;
while(t--){
tc();
}
return (0-0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded