QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131120#6300. Best Carry Player 2qRE 0ms0kbC++141.6kb2023-07-26 14:10:312023-07-26 14:10:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-26 14:10:34]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-07-26 14:10:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO{
	template<typename T> void read(T &x){ x=0; bool f=0; char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch^48); if(f) x=-x; }
	template<typename T> void write(T x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
}
const int U=38,C=20,K=2;
using i128=__int128;
int t;
int k,s[U];
i128 x,f[U][C][K],p[U];//f[i][j][0/1]表示当前考虑到第i位,进位了j次,当前位是否进位的最小答案 
void init(){
	p[0]=1;
	for(int i=1;i<U;i++) p[i]=p[i-1]*(i128)10;
}
void work(){
	IO::read(x),IO::read(k);
	int n=0;
	for(int tmp=x;tmp;s[++n]=tmp%10,tmp/=10);
	if(!k){
		int pos=n+1;
		for(int i=1;i<=n;i++) if(s[i]!=9){
			pos=i;
			break;
		}
		putchar('1');
		for(int i=1;i<pos;i++) putchar('0');
		puts("");
		return ;
	} 
	n+=k;
	memset(f,0x3f,sizeof f);
	i128 INF=f[0][0][0];
	for(int i=1;i<=36;i++) f[i][0][0]=0;
	for(int i=1;i<=36;i++){
		puts("ads");
		for(int j=0;j<=i;j++){
			f[i][j][0]=min(f[i][j][0],f[i-1][j][0]);
			if(s[i]>0&&j) f[i][j][1]=min(f[i][j][1],f[i-1][j][0]+p[i]*(10-s[i]));
			if(j) f[i][j][1]=min(f[i][j][1],f[i-1][j-1][1]+p[i]*(10-s[i]-1));
			if(s[i]<9&&j) f[i][j][0]=min(f[i][j][0],f[i-1][j][1]);
		}
	}
	i128 ans=min(f[n][k][0],f[n][k][1]); 
	IO::write(ans==INF?-1:ans),puts("");
}
int main(){
	
	init();
//	IO::write(p[38]);
	IO::read(t);
	for(;t--;) work();
	return 0;
}
/*
4
12345678 0
12345678 5
12345678 18
990099 5

1
54322
999999999987654322
9910
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:


result: