QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105312 | #6300. Best Carry Player 2 | George_Plover | WA | 2ms | 3576kb | C++23 | 1.4kb | 2023-05-13 21:47:07 | 2023-05-13 21:47:10 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; --i)
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int M = 20;
const ll inf = 1e18;
int T;
ll p[M];
void init() {
p[0] = 1;
rep(i, 1, 18) p[i] = p[i - 1] * 10;
}
void get_min(ll &a, ll b) { a = min(a, b); }
ll x;
int k;
ll dp[M][M][2];
void work() {
scanf("%lld%d", &x, &k);
if (k == 0) {
rep(i, 0, 17) {
int now = x / p[i] % 10;
if (now < 9) {
printf("%lld\n", p[i]);
return;
}
}
printf("%lld\n", p[18]);
}
rep(i, 0, 18) rep(j, 0, k) rep(c, 0, 1) dp[i][j][c] = inf;
dp[0][0][0] = 0;
if (x % 10) dp[0][1][1] = 10 - x % 10;
rep(i, 1, 18) {
int now = x / p[i] % 10;
rep(j, 0, k) {
get_min(dp[i][j][0], dp[i - 1][j][0]);
if (now < 9) get_min(dp[i][j][0], dp[i - 1][j][1]);
if (j) {
if (now)
get_min(dp[i][j][1],
dp[i - 1][j - 1][0] + (10 - now) * p[i]);
get_min(dp[i][j][1], dp[i - 1][j - 1][1] + (9 - now) * p[i]);
}
}
}
printf("%lld\n", dp[18][k][0]);
}
int main() {
init();
scanf("%d", &T);
while (T--) work();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3560kb
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: 3576kb
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 1000000000000000000 1000000000000000000 0
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '1000000000000000000'