QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#108189 | #6300. Best Carry Player 2 | absy | WA | 1ms | 1760kb | C++17 | 1.1kb | 2023-05-23 20:18:39 | 2023-05-23 20:18:42 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
template<typename T>
T read(){
char c=getchar();T x=0;
while(c<48||c>57) c=getchar();
do x=(x<<1)+(x<<3)+(c^48),c=getchar();
while(c>=48&&c<=57);
return x;
}
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
int a[20],len;
ll f[20][20][2][2];
bool vis[20][20][2][2];
ll pw[20];
ll dp(int x,int o,int t,int z){
if(o<0||o>x+1) return INF;
if(x<0){
if(t||z) return INF;
return 0;
}
if(vis[x][o][t][z]) return f[x][o][t][z];
vis[x][o][t][z]=1;
for(int p=0;p<10;++p){
ll res=INF;
for(int s=0;s<2;++s){
if((a[x]+p+s>9)!=t) continue;
if(p) res=min(res,dp(x-1,o-t,s,0));
else res=min(res,dp(x-1,o-t,s,z));
}
if(res<INF) return f[x][o][t][z]=(res+p*pw[x]);
}
return f[x][o][t][z]=INF;
}
void solve(){
memset(vis,0,sizeof vis);
ll x=read<ll>();int k=read<int>();
len=0;
while(x) a[len++]=x%10,x/=10;
pw[0]=1;
for(int i=1;i<19;++i) pw[i]=pw[i-1]*10ll;
printf("%lld\n",dp(18,k,0,1));
}
int main(){
int tc=read<int>();
while(tc--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 1760kb
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: 1516kb
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 4557430888798830399 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '4557430888798830399'