QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#677937 | #6300. Best Carry Player 2 | Tggdb# | WA | 0ms | 3628kb | C++20 | 2.8kb | 2024-10-26 13:42:08 | 2024-10-26 13:42:08 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ll __int128
#define ull unsigned long long
using namespace std;
int f[20][20][2],a[20];
int base[20];
void paralysis(){
int x,k;
cin>>x>>k;
int len=0;
while (x){
a[++len]=x%10;
x/=10;
}
if (a[1]==9&&k==0){
cout<<"-1\n";
return;
}
for (int i=0;i<=18;i++){
for (int j=0;j<=k;j++){
for (int l=0;l<2;l++){
f[i][j][l]=-1;
}
}
}
f[0][0][0]=0;
for (int i=1;i<=18;i++){
for (int j=0;j<=k;j++){
if (f[i-1][j][1]!=-1){
for (int x=0;x<=9;x++){
int now=(x+1+a[i]);
if (now>=10&&j+1<=k){
if (f[i][j+1][1]!=-1){
f[i][j+1][1]=min(f[i][j+1][1],f[i-1][j][1]+base[i-1]*x);
}else{
f[i][j+1][1]=f[i-1][j][1]+base[i-1]*x;
}
}
if (now<10){
if (f[i][j][0]!=-1){
f[i][j][0]=min(f[i][j][0],f[i-1][j][1]+base[i-1]*x);
}else{
f[i][j][0]=f[i-1][j][1]+base[i-1]*x;
}
}
}
}
if (f[i-1][j][0]!=-1){
// cout<<i-1<<" "<<j<<"\n";
for (int x=0;x<=9;x++){
int now=(x+a[i]);
if (now>=10&&j+1<=k){
if (f[i][j+1][1]!=-1){
f[i][j+1][1]=min(f[i][j+1][1],f[i-1][j][0]+base[i-1]*x);
}else{
f[i][j+1][1]=f[i-1][j][0]+base[i-1]*x;
}
}
if (now<10){
// cout<<x<<"\n";
if (f[i][j][0]!=-1){
f[i][j][0]=min(f[i][j][0],f[i-1][j][0]+base[i-1]*x);
}else{
f[i][j][0]=f[i-1][j][0]+base[i-1]*x;
}
}
}
}
}
}
int ans=0;
if (f[18][k][0]!=-1&&f[18][k][1]!=-1){
ans=min(f[18][k][0],f[18][k][1]);
}else if (f[18][k][0]!=-1){
ans=f[18][k][0];
}else if (f[18][k][1]!=-1){
ans=f[18][k][1];
}else{
ans=-1;
}
if (ans==0){
ans=1;
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
base[0]=1;
for (int i=1;i<=18;i++){
base[i]=base[i-1]*10;
}
int T=1;
cin>>T;
while (T--){
paralysis();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
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: 3628kb
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 9000009999900001 99000009999900001 999000009999900001 -1 -1
result:
wrong answer 1st lines differ - expected: '100000', found: '-1'