萌新求助 A 题
查看原帖
萌新求助 A 题
119062
Lates楼主2020/5/23 22:19

RT

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
inline int read(){
	register int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}

string s,st,p,res;
int n,k;
inline bool check1(string a,string b){//a>b?1:0
	if(a.length()==b.length()){
		for(register int i=0;i<a.length();++i){
			if(a[i]==b[i])continue;
			else return a[i]>b[i]?1:0;
		}
	}else return a.length()>b.length()?1:0;
}
int x[200005];
inline void solve(string str){
	for(register int i=0;i<str.length();++i)x[i]=(int)str[i]^'0';
	++x[str.length()-1];
	for(register int i=str.length()-1;i>=1;--i){
		if(x[i]>=10){
			x[i-1]+=x[i]/10;
			x[i]%=10;
		}
	}
	st="";
	for(register int i=0;i<str.length();++i)st=st+(char)(x[i]+48);
}
signed main(){
//	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	n=read(),k=read();
	cin>>s;st=p=res="";
	for(register int i=0;i<k;++i)st+=s[i];
	for(register int i=0;i<k;++i)p+=s[i+k];
	if(check1(p,st))solve(st);
	for(register int i=0;;++i){
		res+=st;
		if(res.length()>=n)break;
	}
	printf("%d\n",n);
	for(register int i=1;i<=n;++i){
		printf("%c",res[i-1]);
	}
	return 0;
}


2020/5/23 22:19
加载中...