Problem Description
Problem Analysis
Since the problem says outputting any one of multiple results is fine
it boils down to asking whether a linear equation in two variables has an integer solution
the data is small, so enumeration can find that integer solution
then just output the pieces
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
| #include<stdio.h>
char s[120];
int main() {
int n,p,q;
while(scanf("%d %d %d",&n,&p,&q)!=EOF) {
scanf("%s",s);
int a=-1,b=-1;
for(int i=0; i<=n; i++) {
for(int j=0; j<=n; j++) {
if(i*p+j*q==n) {
a=i;
b=j;
break;
}
}
}
if(a==-1)
printf("-1\n");
else {
printf("%d\n",a+b);
for(int i=0; i<a; i++) {
for(int j=0; j<p; j++)
printf("%c",s[p*i+j]);
printf("\n");
}
for(int i=0; i<b; i++) {
for(int j=0; j<q; j++)
printf("%c",s[p*a+q*i+j]);
printf("\n");
}
}
}
return 0;
}
|