#include <stdio.h>
#define N 1000000
int main() {
static char cc[N + 1];
static int ll[N], rr[N], ii[N], kk[N];
int n, m, cnt, h, h_, i, j, d, d_;
scanf("%d%s", &n, cc);
cnt = 0;
while (n > 0) {
m = 0;
for (i = 0; i + 1 < n; i++)
if (cc[i] == cc[i + 1]) {
j = i + 1;
while (j < n && cc[j] == cc[i])
j++;
ll[m] = i, rr[m] = j - 1, m++;
i = j - 1;
}
if (m == 0) {
printf("-1\n");
return 0;
}
d_ = -1, h_ = -2;
for (h = 0; h + 1 < m; h++) {
d = ll[h + 1] - rr[h];
if (d_ < d)
d_ = d, h_ = h;
}
d = ll[0] + 1;
if (d_ < d)
d_ = d, h_ = -1;
d = n - rr[m - 1];
if (d_ < d)
d_ = d, h_ = m - 1;
if (h_ == -1)
h_++;
if (h_ == 0 && ll[h_] == 0 && m >= 2)
h_++;
if ((rr[h_] - ll[h_] + 1) % 2 == 0) {
ii[cnt] = ll[h_], kk[cnt] = 2, cnt++;
n -= 2;
for (i = ll[h_]; i < n; i++)
cc[i] = cc[i + 2];
cc[n] = 0;
} else {
ii[cnt] = ll[h_], kk[cnt] = 3, cnt++;
n -= 3;
for (i = ll[h_]; i < n; i++)
cc[i] = cc[i + 3];
cc[n] = 0;
}
}
printf("%d\n", cnt);
for (h = 0; h < cnt; h++)
printf("%d %d\n", ii[h] + 1, kk[h]);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:10:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d%s", &n, cc);
| ^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
292 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
292 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
292 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
292 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |