QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#242901 | #6300. Best Carry Player 2 | neonaht | WA | 1ms | 3448kb | C++17 | 2.1kb | 2023-11-07 18:19:21 | 2023-11-07 18:19:21 |
Judging History
answer
#include <bits/stdc++.h>
#define DEBUG 0
#define CASES 1
#define st first
#define nd second
#define ll long long
using namespace std;
typedef double db;
const int SZ = 2e5 + 7;
const int MX = 1e9 + 7;
const int MOD = 1e9 + 7;
const long long MX2 = 1e18 + 1;
long long dp[20][20][2];
void process(void) {
string x, y;
int k;
cin >> y >> k;
int you = 18-y.size();
// for(int i=0; i<you; i++) x.push_back('0');
x += y;
for(int i=0; i<20; i++) {
for(int j=0; j<20; j++) {
if(j>0) dp[i][j][0] = MX2;
dp[i][j][1] = MX2;
}
}
if(x[x.size()-1] != '0') dp[x.size()-1][1][1] = 10 - (x[x.size()-1] - 48);
for(int i=x.size()-2; i>-1; i--) {
long long cnt = 1, idx = 0;
while(idx < x.size()-1-i) {
cnt *= 10;
idx++;
}
for(int j=1; j<=k; j++) {
long long add0 = cnt*(long long)(10-(x[i]-48));
long long add1 = cnt*(long long)(9-(x[i]-48));
dp[i][j][1] = dp[i+1][j-1][1] + add1;
if(x[i] != '0') dp[i][j][1] = min(dp[i][j][1] ,dp[i+1][j-1][0] + add0);
dp[i][j][0] = dp[i+1][j][0];
if(x[i] != '9') dp[i][j][0] = min(dp[i][j][0], dp[i+1][j][1]);
}
}
long long res = min(dp[0][k][0], dp[0][k][1]);
if(!k) {
int idx = 17, cnt = 0;
while(idx>-1 && x[idx] == '9') {
++cnt;
--idx;
}
cout << '1';
for(int i=0; i<cnt; i++) cout << '0';
}
else if(res == MX2) {
int now = k;
while(now > -1 && dp[0][now][1] >= MX2) now--;
if(now == -1) cout << now;
else {
for(int i=0; i<k-now; i++) cout << '9';
cout << dp[0][now][1];
}
}
else cout << res;
cout << '\n';
return ;
}
int main() {
#ifndef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cin.tie(nullptr)->ios::sync_with_stdio(false);
int t(1);
if(CASES) cin >> t;
while(t--) process();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3396kb
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: 0ms
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:
1 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 99999900001 999999900001 9999999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 1st lines differ - expected: '100000', found: '1'