QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220735 | #6300. Best Carry Player 2 | wushi | WA | 0ms | 3584kb | C++14 | 2.1kb | 2023-10-20 19:11:12 | 2023-10-20 19:11:13 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
//#define int ll
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
int mod = 1e9 + 7, mod2 = 998244353;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
const int N = 4e6 + 10, INF = 0x3f3f3f3f;
ll n, m, k;
int qmi(int a, int b) {
ll res = 1;
while (b) {
if (b & 1)res = res * a % mod;
a = (ll)a * a % mod;
b >>= 1;
}
return res;
}
__int128 lg[50];
__int128 dp[50][26][2][2];
void output(lll x) {
vector<int>d;
if (x == 0) {
d.push_back(0);
}
while (x) {
d.push_back(x % 10);
x /= 10;
}
for (int i = d.size() - 1; i >= 0; i--) {
cout << d[i];
}
cout << '\n';
}
void solve() {
ll x;
cin >> x >> k;
vector<ll>d(50);
int o = 0;
while (x) {
d[o++] = x % 10;
x /= 10;
}
lll ans = 1;
ans *= (ll)1e18;
ans *= (ll)1e18;
for (int i = 0; i < 42; i++) {
for (int j = 0; j < 22; j++) {
for (int h = 0; h < 2; h++) {
for(int o = 0; o < 2; o++)
dp[i][j][h][o] = ans;
}
}
}
lll up = ans;
dp[0][0][0][0] = 0;
for (int i = 0; i < 40; i++) {
for (int j = 0; j <= k; j++) {
for (int h = 0; h < 2; h++) {
for (int o = 0; o < 2; o++) {
if (dp[i][j][h][o] < up) {
lll u = d[i] + h;
if (u > 9) {
dp[i + 1][j + 1][1][o] = min(dp[i + 1][j + 1][1][o], dp[i][j][h][o]);
} else {
lll r = 10 - u;
if (r < 10)dp[i + 1][j + 1][1][1] = min(dp[i + 1][j + 1][1][1], dp[i][j][h][o] + r * lg[i]);
dp[i + 1][j][0][o] = min(dp[i + 1][j][0][o], dp[i][j][h][o]);
if(u != 9) {
dp[i + 1][j][0][1] = min(dp[i + 1][j][0][1], dp[i][j][h][o] + 1 * lg[i]);
}
}
if (j == k && o == 1) {
ans = min(ans, dp[i][j][h][o]);
}
}
}
}
}
}
output(ans);
}
signed main() {
// std::ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// cout << fixed << setprecision(2);
int T = 1;
lg[0] = 1;
for (int i = 1; i < 41; i++) {
lg[i] = lg[i - 1] * 10;
}
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987654322 9901
result:
wrong answer 4th lines differ - expected: '9910', found: '9901'