QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361402 | #6300. Best Carry Player 2 | Zxc200611# | WA | 1ms | 3860kb | C++14 | 1.3kb | 2024-03-23 09:51:31 | 2024-03-23 09:51:31 |
Judging History
answer
/*
给出十进制数 x 以及 k。找出最小的十进制数 y,使得 x+y 在十进制下进位恰好 k 次。
设 f[i][cnt][cry=0/1] 表示低 i 位,进位 cnt 次,i 向 i+1 是否进位,y 最小是多少。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=3e18;
int x,k,cnt0;
int numx[22];
int f[22][22][2];
void clear()
{
for(int i=0;i<=20;i++)
{
numx[i]=0;
for(int cnt=0;cnt<=20;cnt++)
f[i][cnt][0]=f[i][cnt][1]=inf;
}
cnt0=0;
}
void splitX(int x)
{
while(x%10==0)
cnt0++,x/=10;
for(int i=0;x;i++,x/=10)
numx[i]=x%10;
}
signed main()
{
int T;
cin>>T;
for(int _=1;_<=T;_++)
{
cin>>x>>k;
clear();
splitX(x);
if(k==0)
{
int y=1;
while((x/y)%10==9*y)
y*=10;
cout<<y<<'\n';
continue;
}
int pw10=1;
for(int i=0;i<=17;i++,pw10*=10)
{
for(int cnt=0;cnt<=i;cnt++)
{
for(int cry=0;cry<=1;cry++)
{
for(int yi=0;yi<=9;yi++)
{
int ncry=(numx[i]+yi+cry>=10);
int ncnt=cnt+ncry;
f[i][ncnt][ncry]=min<int>(f[i][ncnt][ncry],(i==0?(cnt==0&&cry==0?0:inf):f[i-1][cnt][cry])+yi*pw10);
}
}
}
}
cout<<min<int>(f[17][k][0],f[17][k][1])<<string(cnt0,'0')<<'\n';
}
}
/*
4
12345678 0
12345678 5
123456780000 18
990099 5
*/
Details
Tip: Click on the bar to expand more detailed information
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: 1ms
memory: 3860kb
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:
10 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 10
result:
wrong answer 1st lines differ - expected: '100000', found: '10'