QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#154261 | #6300. Best Carry Player 2 | qzez# | WA | 2ms | 3888kb | C++14 | 1.4kb | 2023-08-31 15:56:58 | 2023-08-31 15:56:58 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e3+5,M=N*40+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
ll x;int k,B[19];
ll dp[19][19][2][2],Po[19];
void Solve(){
int i,j,h;scanf("%lld%d",&x,&k);
Me(dp,0x3f);
for(i=1;i<=18;i++) B[i]=x%10,x/=10;
for(Po[0]=i=1;i<=18;i++) Po[i]=Po[i-1]*10;
dp[0][0][0][0]=0;
for(i=1;i<=18;i++){
for(j=0;j<=k;j++){
for(int o=0;o<2;o++)for(int p=0;p<2;p++){
int w=B[i]+o;
if(w<=9){
dp[i][j][0][p]=min(dp[i][j][0][p],dp[i-1][j][o][p]);
if(!p&&w<9) dp[i][j][0][1]=min(dp[i][j][0][1],dp[i-1][j][o][p]+Po[i-1]);
}
if(j<k){
dp[i][j+1][1][1]=min(dp[i][j+1][1][1],dp[i-1][j][o][p]+Po[i-1]*(10-w));
}
}
}
}
ll ans=min(dp[18][k][0][1],dp[18][k][1][1]);
if(ans>1e18) puts("-1");
else printf("%lld\n",ans);
}
int main(){
int t;
scanf("%d",&t);
// t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
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: 3772kb
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 10000000000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 900000000000000000 -1
result:
wrong answer 11th lines differ - expected: '10000000001', found: '10000000000'