QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129399#6300. Best Carry Player 2yz_lyWA 1ms3600kbC++141.6kb2023-07-22 18:51:452023-07-22 18:51:46

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-22 18:51:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2023-07-22 18:51:45]
  • 提交

answer

#include<bits/stdc++.h>
#define ll __int128
using namespace std;
inline ll read(){
	char ch=getchar();
	ll f=1,x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f=-f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
inline void work(ll k){
	if(k<0){
		putchar('-');
		k=-k;
	}
	if(k>9)
		work(k/10);
	putchar(k%10+'0');
}
ll t,x,dp[41][41][2];
int k;
ll power(ll a,ll b){
    ll sum=1,k=a;
    while(b){
        if(b&1ll)
            sum*=k;
        k*=k;
        b>>=1ll;
    }
    return sum;
}
int main(){
	t=read();
    while(t--){
        x=read();
        k=read();
        if(!k){
            for(int i=1;i<=20;i++){
                ll now=x/(ll)power(10,i-1)%(ll)10;
                if(now!=9){
                    work((ll)power(10,i-1));
                    break;
                }
            }
            putchar('\n');
            continue;
        }
        memset(dp,64,sizeof(dp));
        dp[0][0][0]=0;
        for(int i=1;i<=37;i++){
            ll now=x/(ll)power(10,i-1)%(ll)10;
            for(int j=0;j<=k;j++){
                dp[i][j][0]=(now==(ll)9?dp[i-1][j][0]:min(dp[i-1][j][0],dp[i-1][j][1]));
                if(j)
                    dp[i][j][1]=(now==(ll)0?dp[i-1][j-1][1]+(ll)9*(ll)power(10,i-1):min(dp[i-1][j-1][1]+(9-now)*(ll)power(10,i-1),dp[i-1][j-1][0]+(10-now)*(ll)power(10,i-1)));
            }
        }
        ll ans=min(dp[20][k][0],dp[20][k][1]);
        if(ans>(ll)1e37)
            work(-1);
        else
            work(ans);
        putchar('\n');
    }
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3600kb

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
-1
1000000000000000000

result:

wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '-1'