-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
62 lines (58 loc) · 1.4 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 3e5 + 5;
int s[MAXN],t[MAXN];int n;
char str[MAXN];
inline bool pd(){
FOR(i,1,n){
if(s[i] < t[i]) return 1;
if(s[i] > t[i]) return 0;
}
return 0;
}
int main(){
int L;scanf("%d",&L);
scanf("%s",str+1);n = strlen(str+1);FOR(i,1,n) s[i] = str[i]-'0';
bool flag = 1;FOR(i,1,n) flag &= (s[i]==9);
if((n%L) || flag){
int now = 0;
while(now <= n){
putchar('1');
FOR(i,1,L-1) putchar('0');
now += L;
}
puts("");
return 0;
}
FOR(i,1,L) t[i] = s[i];
FOR(i,L+1,n) t[i] = t[i-L];
if(pd()){
FOR(i,1,n) putchar('0'+t[i]);
puts("");
return 0;
}
++t[L];
ROF(i,L,2){
t[i-1] += t[i]/10;
t[i] %= 10;
}
FOR(i,L+1,n) t[i] = t[i-L];
assert(pd());
FOR(i,1,n) putchar('0'+t[i]);
puts("");
return 0;
}