QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#392914 | #7606. Digital Nim | i_am_noob# | WA | 70ms | 4076kb | C++14 | 2.2kb | 2024-04-17 22:21:04 | 2024-04-17 22:21:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
const int N=18,D=188;
ll dp[N][D][N],pw[N+1];
int sum(ll x){
string s=to_string(x);
int tot=0;
for(auto c: s) tot+=c-'0';
return tot;
}
ll next(int d, ll x){
for(ll i=x+1; ; ++i){
if(sum(i)+d<(i-x)*10) return i;
}
}
void ahcorz(){
ll n; cin >> n;
if(n%10){
cout << "Algosia\n";
return;
}
n/=10;
if(sum(n)<10){
cout << "Bajtek\n";
return;
}
if(n<=100){
int cur=1;
while(cur<n){
cur=next(0,cur);
}
cout << (cur==n?"Bajtek":"Algosia") << "\n";
return;
}
ll cur=1;
for(int i=N-1; i>=2; --i){
int tmp=sum(cur/pw[i+1]);
for(int j=0; j<10; ++j){
ll nxt=dp[i][tmp+j][cur%pw[i]];
ll nw=cur-cur%pw[i]+nxt;
if(nw>n) break;
cur=nw;
if(j<9) cur=next(0,cur);
}
}
while(cur<n) cur=next(0,cur);
cout << (cur==n?"Bajtek":"Algosia") << "\n";
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
pw[0]=1;
for(int i=1; i<=N; ++i) pw[i]=pw[i-1]*10;
for(int d=0; d<D; ++d){
for(int j=0; j<N; ++j){
dp[2][d][j]=j;
while(1){
int nxt=next(d,dp[2][d][j]);
if(nxt>=pw[2]) break;
dp[2][d][j]=nxt;
}
//cout << d << ' ' << j << ' ' << dp[2][d][j] << endl;
}
}
for(int i=3; i<N; ++i) for(int d=0; d<D-10; ++d){
for(int j=0; j<N; ++j){
dp[i][d][j]=j;
for(int cur=0; cur<10; ++cur){
if(dp[i][d][j]-cur*pw[i-1]<0){
dp[i][d][j]=-1;
break;
}
dp[i][d][j]=dp[i-1][d+cur][dp[i][d][j]-cur*pw[i-1]]+pw[i-1]*cur;
if(cur<9) dp[i][d][j]=next(d,dp[i][d][j]);
}
//if(dp[i][d][j]!=-1) cout << i << ' ' << d << ' ' << j << ' ' << dp[i][d][j] << endl;
}
}
int t=1; cin >> t;
while(t--) ahcorz();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 64ms
memory: 4076kb
input:
4 1 10 42 190
output:
Algosia Bajtek Algosia Algosia
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 68ms
memory: 4076kb
input:
1 1
output:
Algosia
result:
ok single line: 'Algosia'
Test #3:
score: -100
Wrong Answer
time: 70ms
memory: 4028kb
input:
10000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia Bajtek Algosia Algosia Algosia Algosia Algosia Algosia Algosia Algosia...
result:
wrong answer 1980th lines differ - expected: 'Bajtek', found: 'Algosia'