QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106661 | #6300. Best Carry Player 2 | xuzhihaodedie | WA | 1ms | 3472kb | C++14 | 1.8kb | 2023-05-18 15:28:36 | 2023-05-18 15:28:38 |
Judging History
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() {
ull n;
int k;
cin>>n>>k;
for(int i=0;i<=20;i++) num[i]=0;
memset(dp,-1,sizeof dp);
memset(vis,0,sizeof vis);
int x=n;
int res=0;
int cnt=0;
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 ;
}
//cout<<"OK"<<endl;
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: 1ms
memory: 3472kb
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: 3448kb
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'