QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129924#6300. Best Carry Player 2FffooooWA 1ms4028kbC++201.6kb2023-07-23 08:29:422023-07-23 08:29:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 08:29:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4028kb
  • [2023-07-23 08:29:42]
  • 提交

answer

#include<bits/stdc++.h>
#define int __int128
using namespace std;
inline int read() {
	int x=0,f=1; char ch=getchar();
	while( ch<'0' || ch>'9' ) { if(ch=='-') f=-f; ch=getchar(); }
	while( ch>='0' && ch<='9' ) { x=(x<<1)+(x<<3)+ch-48; ch=getchar(); }
	return x*f;
}
inline void write(int x) {
	if(x<0) putchar('-'), x=-x;
	if(x>9) write(x/10);
	putchar( x%10+48 );
}
const int N=100;
int t,x,k,s[N];
int dp[N][N][2];
signed main() {
	t=read();
	while(t--) {
		x=read();k=read();
		int n=0,TNT=x;
		//write(x); cout<<" ";
		memset(s,0,sizeof(s)); 
		while(TNT) { n++; s[n]=TNT%10; TNT/=10; }
		n+=k;
//		for(int i=1;i<=n;i++) write(s[i]),cout<<" ";
//		puts("");
		memset(dp,0x3f,sizeof(dp));
		for(int i=0;i<100;i++) dp[i][0][0]=0;
		int sb=1;
		for(int i=1;i<=37;i++) {
			for(int j=0;j<=min(i,k);j++) {
				dp[i][j][0]=dp[i-1][j][0];
				if( s[i]!=9 ) if( j>=1 ) dp[i][j][0]=min( dp[i][j][0],dp[i-1][j][1] );
				if( s[i]!=0 && j>=1 ) dp[i][j][1]=dp[i-1][j-1][0]+sb*(10-s[i]);
				if(j>=1) dp[i][j][1]=min( dp[i][j][1],dp[i-1][j-1][1]+sb*(10-s[i]-1) );
//				write(i); cout<<" "; write(j); cout<<" ";
//				write(dp[i][j][0]); cout<<" "; write(dp[i][j][1]); cout<<" \n";
			}
			sb=sb*10;
		}
		int ans=min( dp[n][k][0],dp[n][k][1] );
//		write(ans); cout<<" ";
		if(ans==0) {
			int xp=0;
			for(int i=1;i<=n;i++) if(s[i]!=9) { xp=i; break; }
//			write(xp),cout<<" ";
			if(xp) printf("%d",1);
			else printf("-1");
			for(int i=1;i<xp;i++) putchar('0');
		} else write(ans);
		puts("");
	}
	return 0;
}
/*
4
12345678 0
12345678 5
12345678 18
990099 5
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4028kb

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: 3936kb

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:

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

result:

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