QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297900#6300. Best Carry Player 2PlentyOfPenalty#WA 1ms3532kbC++201.3kb2024-01-05 13:13:042024-01-05 13:13:04

Judging History

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

  • [2024-01-05 13:13:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3532kb
  • [2024-01-05 13:13:04]
  • 提交

answer

#include<bits/stdc++.h>
#ifndef memset0
#define endl '\n'
#endif
#define all(x) begin(x),end(x)
using namespace std;
using ll=long long;
using lll=__int128;
const int L=38,X=20;
int T,x,n,a[L];
ll v;
lll dp[L][2][X],bit[L];
void write(lll x){
	if(x==0){cout<<0;return;}
	if(x>9)write(x/10);
	cout<<(int)(x%10);
}
inline void upd(lll &x,lll y){
	if(x==-1||y<x)x=y;
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("C.in","r",stdin);
#endif
	cin.tie(0)->sync_with_stdio(0);
	bit[0]=1;
	for(int i=1;i<L;i++)bit[i]=bit[i-1]*10;
	// write(bit[L-1]),cout<<endl;
	cin>>T;
	while(T--){
		cin>>v>>x;
		memset(a,0,sizeof(a));
		memset(dp,-1,sizeof(dp));
		n=0;
		while(v){
			a[n++]=v%10;
			v/=10;
		}
		if(x==0){
			if(a[0]<9){
				cout<<1<<endl;
			}else{
				cout<<(-1)<<endl;
			}
			continue;
		}
		for(int u=0;u<=9;u++){
			int v=u+a[0];
			upd(dp[0][v>9][v>9],u);
		}
		for(int i=0;i+1<L;i++)
			for(int j=0;j<2;j++)
				for(int k=0;k<=x;k++)
					if(dp[i][j][k]!=-1){
						// cout<<i<<","<<j<<","<<k<<"::",write(dp[i][j][k]),cout<<endl;
						for(int u=0;u<=9;u++){
							int v=u+j+a[i+1];
							upd(dp[i+1][v>9][k+(v>9)],u*bit[i+1]+dp[i][j][k]);
						}
					}
		lll ans=-1;
		for(int j=0;j<2;j++)
			if(dp[L-1][j][x]!=-1){
				upd(ans,dp[L-1][j][x]);
			}
		write(ans),cout<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3496kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3532kb

input:

21
999990000099999 0
999990000099999 1
999990000099999 2
999990000099999 3
999990000099999 4
999990000099999 5
999990000099999 6
999990000099999 7
999990000099999 8
999990000099999 9
999990000099999 10
999990000099999 11
999990000099999 12
999990000099999 13
999990000099999 14
999990000099999 15
999...

output:

-1
10000
1000
100
10
1
900001
9900001
99900001
999900001
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
-1

result:

wrong answer 1st lines differ - expected: '100000', found: '-1'