QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#678034 | #6300. Best Carry Player 2 | Tggdb# | WA | 0ms | 3596kb | C++20 | 2.9kb | 2024-10-26 13:53:27 | 2024-10-26 13:54:13 |
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;
while (x){
a[++len]=x%10;
x/=10;
}
if (a[1]==9&&k==0){
cout<<"-1\n";
return;
}
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){
for (int x=0;x<=9;x++){
int now=(x+1+a[i]);
if (now>=10&&j+1<=k){
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;
}
}
if (now<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){
// cout<<i-1<<" "<<j<<"\n";
for (int x=0;x<=9;x++){
int now=(x+a[i]);
if (now>=10&&j+1<=k){
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;
}
}
if (now<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){
ans=1;
}
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: 3532kb
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: 3596kb
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 -1 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000
result:
wrong answer 1st lines differ - expected: '100000', found: '-1'