QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129469 | #6300. Best Carry Player 2 | sinsop90 | WA | 1ms | 3656kb | C++14 | 928b | 2023-07-22 19:52:58 | 2023-07-22 19:57:01 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int T, n, k, f[25][25][2], vis[25][25][2];
void solve() {
scanf("%lld%lld", &n, &k);
memset(vis, 0, sizeof(vis)), memset(f, 0x3f3f3f, sizeof(f));
int now = 1;
vis[0][0][0] = 1, f[0][0][0] = 0;
for(int i = 1;i <= 18;i++) {
int g = n / now % 10;
for(int j = 0;j <= k;j++) {
if(vis[i - 1][j][0]) {
f[i][j + 1][1] = min(f[i][j + 1][1], f[i - 1][j][0] + now * (10 - g));
f[i][j][0] = min(f[i][j][0], f[i - 1][j][0]);
vis[i][j + 1][1] = vis[i][j][0] = 1;
}
if(vis[i - 1][j][1]) {
f[i][j + 1][1] = min(f[i][j + 1][1], f[i - 1][j][1] + now * (10 - 1 - g));
if(g != 9) f[i][j][0] = min(f[i][j][0], f[i - 1][j][1]), vis[i][j][0] = 1;
vis[i][j + 1][1] = 1;
}
}
now *= 10;
}
printf("%lld\n", min(f[18][k][1], f[18][k][0]));
}
signed main() {
scanf("%lld", &T);
while(T --) solve();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3656kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
0 54322 999999999987654322 9910
result:
wrong answer 1st lines differ - expected: '1', found: '0'