QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253550#6300. Best Carry Player 2SATSKYWA 1ms3656kbC++201.4kb2023-11-17 08:21:432023-11-17 08:21:44

Judging History

你现在查看的是最新测评结果

  • [2023-11-17 08:21:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2023-11-17 08:21:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ll=long long;const ll inf=3e18;
int dp[30][30][2];
struct S
{
	vector<vector<vector<ll>>>dp;
	void solve()
	{
		int c0=0,di[19];ll bas=1;
		dp.resize(20,vector<vector<ll>>(20,vector<ll>(2,inf)));
		ll x,k;cin>>x>>k;
		if(k==18)
		{
			ll bs=1;for(int i=1;i<=18;i++)bs*=10;cout<<bs-x;
			while(c0--)cout<<'0';cout<<'\n';return;
		}
		else if(k==0)
		{
			if(c0){cout<<"1\n";return;}ll res=1;
			while(x%10==9)x/=10,res*=10;cout<<res<<'\n';return;
		}
		while(x%10==0)x/=10,c0++;dp[0][0][0]=0;
		for(int i=1;i<=18;i++)di[i]=x%10,x/=10;
		for(int i=1;i<=18;i++,bas*=10)
		{
			for(int j=0;j<=18;j++)
			{
				dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][0]);
				if(di[i]!=9)dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][1]);
				dp[i][j+1][1]=min(dp[i][j+1][1],dp[i-1][j][1]+bas*(9-di[i]));
				if(di[i]!=0)dp[i][j+1][1]=min(dp[i][j+1][1],dp[i-1][j][0]+bas*(10-di[i]));
				//cout<<"now"<<i<<"over"<<j<<"L"<<0<<":"<<dp[i][j][0]<<'\n';
				//cout<<"now"<<i<<"over"<<j<<"L"<<1<<":"<<dp[i][j][1]<<'\n';
			}
		}		
		ll res=dp[18][k][0];cout<<res;while(c0--)cout<<'0';cout<<'\n';return;
	}
};
int main()
{
	//freopen("3.in","r",stdin);
	//cout<<fixed<<setprecision(12);
	ios::sync_with_stdio(0);cin.tie(0);
	int t=1;cin>>t;
	//clock_t a=clock();
	while(t--){S SS;SS.solve();}
	//cout<<"Time:"<<double(clock()-a)<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3656kb

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: 3652kb

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
900000000000000000
1000000000000000000

result:

wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '900000000000000000'