QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#480479 | #7616. Jump Graph | ucup-team052# | RE | 0ms | 0kb | C++14 | 1.7kb | 2024-07-16 16:01:54 | 2024-07-16 16:01:54 |
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define D(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
using LL=long long;
int T;
LL pw[19];
int dp[19][18*10][18];
int bin[1000005];
int calc(LL x){
return bin[x%1000000]+bin[x/1000000%1000000]+bin[x/1000000000000LL];
}
LL nex(LL x,int s){
assert(x%10==0);
LL y=x+10;
while(y-calc(y)-s<=x)y+=10;
return y;
}
int main(){
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
bin[0]=0;
rep(i,1,1000000)bin[i]=bin[i/10]+i%10;
pw[0]=1;
rep(i,1,18)pw[i]=pw[i-1]*10;
memset(dp,-1,sizeof(dp));
rep(i,3,17){
rep(s,0,179){
rep(x,0,17){ // 10^i * s + 10x => 10^i * s + dp
D("%d %d %d\n",i,s,x);
// dp < 10^i
if(i==3){
LL cur=x*10;
while(cur<pw[i]){
dp[i][s][x]=cur;
cur=nex(cur,s);
}
}else{
LL cur=dp[i-1][s][x];
D("cur=%lld\n",cur);
while(cur<pw[i]){
dp[i][s][x]=cur;
/*D("! %lld\n",cur);
if(i==6&&s==153&&x==0&&cur==998950){
D("!\n");
}*/
cur=nex(cur,s);
if(cur>=pw[i])break;
cur=cur/pw[i-1]*pw[i-1]+dp[i-1][s+cur/pw[i-1]%10][cur%pw[i-1]/10];
}
}
}
}
}
cin>>T;
while(T--){
LL x;
cin>>x;
if(x%10!=0){
puts("Algosia");
continue;
}
LL cur=10;
per(i,18,3){
LL t=dp[i][calc(cur/pw[i])][cur%pw[i]/10];
t=nex(cur/pw[i]*pw[i]+t,0);
if(t<=x){
cur=t;
++i;
}
}
while(cur<x){
cur=nex(cur,0);
}
puts(cur==x?"Bajtek":"Algosia");
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
6 1 6 3 2 5 4