QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176853#5460. Sum of NumbersCidoai#WA 393ms1532kbC++142.0kb2023-09-12 08:37:332023-09-12 08:37:33

Judging History

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

  • [2023-09-12 08:37:33]
  • 评测
  • 测评结果:WA
  • 用时:393ms
  • 内存:1532kb
  • [2023-09-12 08:37:33]
  • 提交

answer

#include<cstdio>
inline int read(){
	int x=0;
	int f=0,ch=0;
	while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
	while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
	return f?-x:x;
}
inline void write(int x,char end=' '){
	if(x==0){
		putchar('0');
		putchar(end);
		return;
	}
	if(x<0) putchar('-'),x=-x;
	int ch[70]={0},cnt=0;
	while(x){
		ch[cnt++]=(int)(x%10);
		x/=10;
	}
	while(cnt--) putchar(ch[cnt]+48);
	putchar(end);
}
const int N=2e5+5;
int n,k;
char s[N];
int num[N];
int ans[N];
int now[N];
int nowlen,anslen;
int a[N];
inline int max(int x,int y){return x>y?x:y;}
inline void addto(int l,int r){
	int top=0;
	for(int i=r;i>=l;--i){
		num[top++]=s[i]-'0';
	}
	nowlen=max(nowlen,top)+1;
	for(int i=top;i<nowlen;++i) num[i]=0;
	for(int i=0;i<nowlen;++i){
		now[i]+=num[i];
		now[i+1]+=now[i]/10;
		now[i]%=10;
	}
	while(now[nowlen-1]==0) --nowlen;
}
inline bool jud(){
	if(nowlen<anslen) return 1;
	if(nowlen>anslen) return 0;
	for(int i=nowlen-1;i>=0;--i){
		if(now[i]<ans[i]) return 1;
		if(now[i]>ans[i]) return 0;
	}
	return 0;
}
inline void dfs(int to){
	if(to>k){
		bool flag=1;
		for(int i=0;i<=k;++i){
			if(a[i]>=a[i+1]){
				flag=0;
				break;
			}
		}
		if(flag){
			for(int i=0;i<=k;++i){
				addto(a[i]+1,a[i+1]);
			}
			if(jud()){
				anslen=nowlen;
				for(int i=0;i<anslen;++i) ans[i]=now[i],now[i]=0;
				nowlen=0;
			}
			for(int i=0;i<nowlen;++i) now[i]=0;
			nowlen=0;
		}
		return;
	}
	dfs(to+1);
	a[to]++;
	dfs(to+1);
	a[to]-=2;
	dfs(to+1);
}
int main(){
	int T=read();
	while(T--){
		n=read(),k=read();
		scanf("%s",s+1);
		int pos=(n-1)/(k+1)+1;
		for(int i=1;i<=k;++i) a[i]=pos*i;
		a[0]=0,a[k+1]=n;
		for(int i=0;i<=k;++i){
			addto(a[i]+1,a[i+1]);
		}
		anslen=nowlen;
		for(int i=0;i<anslen;++i) ans[i]=now[i],now[i]=0;
		nowlen=0;
		dfs(1);
		if(anslen==0) puts("0");
		else{
			for(int i=anslen-1;i>=0;--i) putchar(ans[i]+'0');
			puts("");
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 1496kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 393ms
memory: 1532kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
2761995194040864129073508116367632383170668856526662171865948656204830936976588397234920132290981872692557217372...

result:

wrong answer 2nd lines differ - expected: '133089789665597477403558640654...7219813869366061308627573151461', found: '276199519404086412907350811636...3854546828582269426842280313661'