QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212819 | #6300. Best Carry Player 2 | ucup-team198 | WA | 0ms | 4092kb | C++23 | 1.9kb | 2023-10-13 20:51:44 | 2023-10-13 20:51:44 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
// #define debug(x) cout<<"[debug]"#x<<"="<<x<<endl
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ld eps=1e-8;
const int INF=0x3f3f3f3f,mod=998244353;
typedef unsigned long long ull;
const ull INFF=0x3f3f3f3f3f3f3f3f;
#ifndef ONLINE_JUDGE
#define debug(...)
#include<debug>
#else
#define debug(...)
#endif
const int N=20;
ull dp[N][N][2];//前i位,当前已经进位了j次,并且第i位是否进位, min
ull bt[N];
char s[N];
void solve()
{
scanf("%s",s+1);
int n=strlen(s+1);
reverse(s+1,s+n+1);
for(int i=n+1;i<=18;i++) s[i]='0';
int k;
scanf("%d",&k);
n=18;
if(k==0)
{
string res;
int id=0;
while(s[id]=='9')
{
res.push_back(s[id++]);
}
res.push_back('1');
reverse(res.begin(),res.end());
cout<<res<<endl;
return ;
}
for(int i=0;i<=n;i++) for(int j=0;j<=min(i,k);j++) for(int t=0;t<2;t++) dp[i][j][t]=1E19;
dp[0][0][0]=0;
for(int i=1;i<=n;i++)
{
int c=s[i]-'0';
for(int ty=0;ty<2;ty++)
{
for(int las=0;las<=min(i-1,k);las++)
{
for(int w=0;w<=9;w++)
{
int val=c+w+ty;
int ty2=val/10;
int now=las+ty2;
dp[i][now][ty2]=min(dp[i][now][ty2],dp[i-1][las][ty]+bt[i]*w);
debug(i,now,ty2,dp[i][now][ty2]);
}
}
}
}
ull res=min(dp[n][k][0],dp[n][k][1]);
if(res>=1E19) puts("-1");
else printf("%lld\n",res);
}
int main()
{
bt[1]=1;
for(int i=2;i<=18;i++) bt[i]=bt[i-1]*10;
int T;
scanf("%d",&T);
while(T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3752kb
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: 4092kb
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'