QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106660#6300. Best Carry Player 2xuzhihaodedieWA 2ms3556kbC++141.8kb2023-05-18 15:27:252023-05-18 15:27:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-18 15:27:29]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3556kb
  • [2023-05-18 15:27:25]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define PII pair<int,int>
using namespace std;
const int N=25;
const int mod=985661441;
int num[N];
int vis[N][N][2];
ull dp[N][N][2];
ull pw[N];
ull dfs(int pos,int sum,int flag) {
    if(pos==0) {
		if(flag||sum) return 9e18;
		else return 0;
 	}
	if(sum>pos) return 9e18;
	if(vis[pos][sum][flag]) return dp[pos][sum][flag];
	vis[pos][sum][flag]=1;
    if(num[pos]==9) {
        if(!flag) {
            dp[pos][sum][0]=dfs(pos-1,sum,0);
        } else {
            dp[pos][sum][1]=min(dfs(pos-1,sum-1,0)+pw[pos-1],dfs(pos-1,sum-1,1));
        }
    } else {
        if(!flag) {
            dp[pos][sum][0]=min(dfs(pos-1,sum,0),dfs(pos-1,sum,1));
        } else {
            dp[pos][sum][1]=min(dfs(pos-1,sum-1,0)+(10-num[pos])*pw[pos-1],dfs(pos-1,sum-1,1)+(9-num[pos])*pw[pos-1]);
        }
    }
    dp[pos][sum][flag]=min(dp[pos][sum][flag],(ull)9e18);
	return dp[pos][sum][flag];
}
void solve() {
	int n,k;
    cin>>n>>k;
    int res=0,cnt=0;
    memset(num,0,sizeof num);
    memset(dp,-1,sizeof dp);
    memset(vis,0,sizeof vis);
    int x=n;
    while(x%10==0) x/=10,res++;
    while(x) {
        num[++cnt]=x%10;
        x/=10;
    }
    if(k==0) {
		cnt=0;
		x=n;
		while(x) {
			num[++cnt]=x%10;
			x/=10;
		}
		for(int i=1; i<=cnt; i++) {
			if(num[i]!=9) {
				printf("1");
				for(int j=1; j<i; j++) printf("0");
				puts("");
				return ;
			}
		}
		printf("1");
		for(int i=1;i<=cnt;i++) printf("0");
		puts("");
		return ;
	}
    printf("%llu",min(dfs(18,k,0),dfs(18,k,1)));
	for(int i=1; i<=res; i++) printf("0");
	puts("");
}

signed main() {
	int T=1;
	cin>>T;
    pw[0]=1;
    for(int i=1;i<=19;i++) pw[i]=pw[i-1]*10;
	while(T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3480kb

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: 2ms
memory: 3556kb

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
10000000000
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
1000000000000000000

result:

wrong answer 11th lines differ - expected: '10000000001', found: '10000000000'