QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212830 | #6307. Chase Game 2 | ucup-team198 | WA | 1ms | 3672kb | C++23 | 1.9kb | 2023-10-13 20:56:04 | 2023-10-13 20:56:04 |
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=1;
while(s[id]=='9')
{
res.push_back('0');
id++;
}
res.push_back('1');
reverse(res.begin(),res.end());
// debug(res);
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: 0
Wrong Answer
time: 1ms
memory: 3672kb
input:
4 2 1 2 4 1 2 2 3 3 4 4 1 2 2 3 2 4 5 1 2 2 3 3 4 3 5
output:
8 9998 99 998
result:
wrong answer 1st numbers differ - expected: '-1', found: '8'