QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#678318 | #6300. Best Carry Player 2 | Tggdb# | WA | 0ms | 3720kb | C++20 | 2.8kb | 2024-10-26 14:37:45 | 2024-10-26 14:37:51 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ll __int128
#define ull unsigned long long
using namespace std;
ll f[37][20][2];
int a[37];
ll base[37];
void write(ll x){
if (x>9){
write(x/10);
}
putchar(x%10+'0');
}
void paralysis(){
int x,k;
cin>>x>>k;
int len=0;
memset(a,0,sizeof(a));
while (x){
a[++len]=x%10;
x/=10;
}
for (int i=0;i<=36;i++){
for (int j=0;j<=k;j++){
for (int l=0;l<2;l++){
f[i][j][l]=-1;
}
}
}
f[0][0][0]=0;
for (int i=1;i<=36;i++){
for (int j=0;j<=k;j++){
if (f[i-1][j][1]!=-1){
if (j+1<=k){
int x=9-a[i];
if (f[i][j+1][1]!=-1){
f[i][j+1][1]=min(f[i][j+1][1],f[i-1][j][1]+base[i-1]*x);
}else{
f[i][j+1][1]=f[i-1][j][1]+base[i-1]*x;
}
}
int x=0;
if (x+a[i]+1<10){
if (f[i][j][0]!=-1){
f[i][j][0]=min(f[i][j][0],f[i-1][j][1]+base[i-1]*x);
}else{
f[i][j][0]=f[i-1][j][1]+base[i-1]*x;
}
}
}
if (f[i-1][j][0]!=-1){
if (j+1<=k){
int x=10-a[i];
if (f[i][j+1][1]!=-1){
f[i][j+1][1]=min(f[i][j+1][1],f[i-1][j][0]+base[i-1]*x);
}else{
f[i][j+1][1]=f[i-1][j][0]+base[i-1]*x;
}
}
int x=0;
if (x+a[i]<10){
// cout<<x<<"\n";
if (f[i][j][0]!=-1){
f[i][j][0]=min(f[i][j][0],f[i-1][j][0]+base[i-1]*x);
}else{
f[i][j][0]=f[i-1][j][0]+base[i-1]*x;
}
}
}
}
}
ll ans=0;
if (f[36][k][0]!=-1&&f[36][k][1]!=-1){
ans=min(f[36][k][0],f[36][k][1]);
}else if (f[36][k][0]!=-1){
ans=f[36][k][0];
}else if (f[36][k][1]!=-1){
ans=f[36][k][1];
}else{
cout<<"-1\n";
return;
}
if (ans==0){
for (int i=1;i<=len+1;i++){
if (a[i]!=9){
ans=base[i-1];
break;
}
}
}
write(ans);
puts("");
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
base[0]=1;
for (int i=1;i<=36;i++){
base[i]=base[i-1]*10;
}
int T=1;
cin>>T;
while (T--){
paralysis();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 3720kb
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 1000000000000000000
result:
wrong answer 11th lines differ - expected: '10000000001', found: '10000000000'