QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#257604 | #6300. Best Carry Player 2 | Crying | WA | 1ms | 3744kb | C++17 | 1.6kb | 2023-11-19 10:58:24 | 2023-11-19 10:58:24 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
typedef __int128 i128;
const ll MAXN = 50,M = 36;
const i128 INF = 1e37;
void tomin(i128& x,i128 y){x = min(x,y);}
ll T,n,k,a[MAXN];
i128 dp[MAXN][MAXN][2],pw[MAXN];
void outp(i128 a){
if(a<10){
cout<<(int)(a);
return;
}
outp(a/10);
cout<<(int)(a%10);
}
void solve(){
cin>>n>>k;
ll num = n;
rep(i,1,M)a[i] = num%10,num /= 10;
rep(i,0,M)rep(j,0,k)rep(c,0,1)dp[i][j][c] = INF;
dp[0][0][0] = 0;
rep(i,1,M){
rep(j,0,k)rep(c,0,1)if(dp[i-1][j][c] != INF){
i128 val = dp[i-1][j][c];
ll x = a[i]+c;
if(x==10){
tomin(dp[i][j+1][1],val);
}else{
//不进位
tomin(dp[i][j][0],val);
//进位
if(x){
ll y=10-x;
tomin(dp[i][j+1][1],val+y*pw[i]);
}
}
}
}
ll R = min(dp[M][k][0],dp[M][k][1]);
if(R == INF){
cout<<"-1\n";
}else{
if(R==0){ //corner case
assert(k==0);
rep(i,1,M)if(a[i] != 9){
outp(pw[i]);cout<<"\n";
return;
}
assert(0);
return;
}
outp(R);cout<<"\n";
}
}
int main(){
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
ios::sync_with_stdio(false);cin.tie(0);
pw[1] = 1;rep(i,2,M)pw[i] = pw[i-1] * 10;
cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3744kb
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: 3708kb
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 3036633892082024448 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '3036633892082024448'