QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#154262#6300. Best Carry Player 2qzez#WA 2ms4036kbC++141.4kb2023-08-31 15:59:372023-08-31 15:59:38

Judging History

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

  • [2023-08-31 15:59:38]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4036kb
  • [2023-08-31 15:59:37]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e3+5,M=N*40+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
ll x;int k,B[19];
ll dp[19][19][2][2],Po[19];
void Solve(){
	int i,j,h;scanf("%lld%d",&x,&k);
	Me(dp,0x3f);
	for(i=1;i<=18;i++) B[i]=x%10,x/=10;
	for(Po[0]=i=1;i<=18;i++) Po[i]=Po[i-1]*10;
	dp[0][0][0][0]=0;
	for(i=1;i<=18;i++){
		for(j=0;j<=k;j++){
			for(int o=0;o<2;o++)for(int p=0;p<2;p++){
				int w=B[i]+o;
				if(w<=9){
					dp[i][j][0][p]=min(dp[i][j][0][p],dp[i-1][j][o][p]);
					if(!p&&w<9) dp[i][j][0][1]=min(dp[i][j][0][1],dp[i-1][j][o][p]+Po[i-1]);
				} 
				if(j<k&&w){
					dp[i][j+1][1][1]=min(dp[i][j+1][1][1],dp[i-1][j][o][p]+Po[i-1]*(10-w));
				} 
			}
		}
	}
	ll ans=min(dp[18][k][0][1],dp[18][k][1][1]);
	if(ans>1e18) puts("-1");
	else printf("%lld\n",ans);
}
int main(){
	int t;
	scanf("%d",&t);
	// t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3992kb

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

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
-1

result:

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