QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#128955 | #6300. Best Carry Player 2 | yz_ly | WA | 1ms | 3456kb | C++14 | 1.6kb | 2023-07-21 17:15:05 | 2023-07-21 17:15:08 |
Judging History
answer
#include<bits/stdc++.h>
#define ll __int128
using namespace std;
inline ll read(){
char ch=getchar();
ll f=1,x=0;
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-f;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void work(ll k){
if(k<0){
putchar('-');
k=-k;
}
if(k>9)
work(k/10);
putchar(k%10+'0');
}
ll t,x,dp[21][21][2];
int k;
ll power(ll a,ll b){
ll sum=1,k=a;
while(b){
if(b&1ll)
sum*=k;
k*=k;
b>>=1ll;
}
return sum;
}
int main(){
t=read();
while(t--){
x=read();
k=read();
if(!k){
for(int i=1;i<=20;i++){
ll now=x/(ll)power(10,i-1)%(ll)10;
if(now!=9){
work((ll)power(10,i-1));
break;
}
}
putchar('\n');
continue;
}
memset(dp,64,sizeof(dp));
dp[0][0][0]=0;
for(int i=1;i<=20;i++){
ll now=x/(ll)power(10,i-1)%(ll)10;
for(int j=0;j<=k;j++){
dp[i][j][0]=(now==(ll)9?dp[i-1][j][0]:min(dp[i-1][j][0],dp[i-1][j][1]));
if(j)
dp[i][j][1]=(now==(ll)0?dp[i-1][j-1][1]+(ll)9*(ll)power(10,i-1):min(dp[i-1][j-1][1]+(9-now)*(ll)power(10,i-1),dp[i-1][j-1][0]+(10-now)*(ll)power(10,i-1)));
}
}
ll ans=min(dp[20][k][0],dp[20][k][1]);
if(ans>(ll)1e19)
work(-1);
else
work(ans);
putchar('\n');
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3456kb
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: 1ms
memory: 3444kb
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 -1 1000000000000000000
result:
wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '-1'