QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480479#7616. Jump Graphucup-team052#RE 0ms0kbC++141.7kb2024-07-16 16:01:542024-07-16 16:01:54

Judging History

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

  • [2024-07-16 16:01:54]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [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

output:


result: