QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#152271 | #6300. Best Carry Player 2 | chen_zexing | WA | 1ms | 3696kb | C++17 | 2.1kb | 2023-08-27 22:08:50 | 2023-08-27 22:08:50 |
Judging History
answer
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define li __int128_t
li dp[35][20][2];
void output(li x){
if(!x) return;
output(x/10);
printf("%d",int(x%10));
}
int main() {
int T = 1, kase = 0;
cin >> T;
while (T--) {
long long n;
int k;
scanf("%lld%d",&n,&k);
if(!k){
li base=1;
for(int i=1;;i++,base*=10){
int r=n%10;
n/=10;
if(r!=9){
output(base);
puts("");
break;
}
}
continue;
}
memset(dp,-1,sizeof(dp));
dp[0][0][0]=0;
li base=1;
for(int i=1;;i++,base*=10){
int r=n%10;
n/=10;
for(int j=0;j<=k;j++)
for(int l=0;l<2;l++) {
if (!l){
dp[i][j][l] = dp[i - 1][j][l];
if(dp[i-1][j][1]!=-1&&r!=9){
if(dp[i][j][l]==-1||dp[i-1][j][1]<dp[i][j][l]) dp[i][j][l]=dp[i-1][j][1];
}
}
else if (j) {
int nd = 10 - r;
if (dp[i - 1][j - 1][0] != -1) dp[i][j][l] = dp[i - 1][j - 1][0] + base * nd;
if (dp[i - 1][j - 1][1] != -1) {
if (dp[i][j][l] == -1 || dp[i - 1][j - 1][1] + base * (nd - 1) < dp[i][j][l])
dp[i][j][l] = dp[i - 1][j - 1][1] + base * (nd - 1);
}
}
/*
if(dp[i][j][l]!=-1){
cout<<i<<" "<<j<<" "<<l<<" ";
output(dp[i][j][l]),puts("");
}
*/
}
if(dp[i][k][0]!=-1){
output(dp[i][k][0]);
puts("");
break;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3696kb
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: 3676kb
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 900000000000000000 1000000000000000000
result:
wrong answer 11th lines differ - expected: '10000000001', found: '10000000000'