#include <stdio.h>
#define N 15
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int pp[N], kk[1 << N], cc[1 << N];
static char good[1 << N];
int n, i, j, b, c, k_, l_;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &pp[i]), pp[i]--;
for (b = 1; b < 1 << n; b++)
kk[b] = kk[b & b - 1] + 1;
k_ = 0, l_ = 0;
for (b = 0; b < 1 << n; b++) {
int incr;
incr = 1;
for (i = -1, j = 0; j < n; j++)
if ((b & 1 << j) != 0) {
if (i != -1 && pp[i] > pp[j]) {
incr = 0;
break;
}
i = j;
}
if (incr)
good[b] = 1, k_ = max(k_, kk[b]);
}
for (b = 0; b < 1 << n; b++)
if (good[b] && kk[b] != k_)
good[b] = 0;
cc[0] = -1;
for (b = 0; b < 1 << n; b++) {
c = 0;
while (c = c - b & b)
if (good[c] && cc[b ^ c]) {
cc[b] = c;
break;
}
if (cc[b])
l_ = max(l_, kk[b] / k_);
}
printf("%d %d\n", l_, k_);
for (b = 0; b < 1 << n; b++)
if (cc[b] && kk[b] == l_ * k_) {
while (b) {
for (i = 0; i < n; i++)
if ((cc[b] & 1 << i) != 0)
printf("%d ", i + 1);
printf("\n");
b ^= cc[b];
}
return 0;
}
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:16:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
16 | kk[b] = kk[b & b - 1] + 1;
| ~~^~~
Main.c:39:16: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
39 | while (c = c - b & b)
| ~~^~~
Main.c:39:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
39 | while (c = c - b & b)
| ^
Main.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &pp[i]), pp[i]--;
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
13 ms |
432 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
16 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
536 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
14 ms |
432 KB |
Output is correct |
11 |
Correct |
15 ms |
436 KB |
Output is correct |
12 |
Correct |
15 ms |
332 KB |
Output is correct |
13 |
Correct |
15 ms |
332 KB |
Output is correct |
14 |
Correct |
16 ms |
332 KB |
Output is correct |
15 |
Correct |
14 ms |
424 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
5 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
13 ms |
432 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
16 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
536 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
14 ms |
432 KB |
Output is correct |
11 |
Correct |
15 ms |
436 KB |
Output is correct |
12 |
Correct |
15 ms |
332 KB |
Output is correct |
13 |
Correct |
15 ms |
332 KB |
Output is correct |
14 |
Correct |
16 ms |
332 KB |
Output is correct |
15 |
Correct |
14 ms |
424 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
5 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
280 KB |
Output is correct |
24 |
Runtime error |
0 ms |
332 KB |
Execution killed with signal 8 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
13 ms |
432 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
16 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
536 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
14 ms |
432 KB |
Output is correct |
11 |
Correct |
15 ms |
436 KB |
Output is correct |
12 |
Correct |
15 ms |
332 KB |
Output is correct |
13 |
Correct |
15 ms |
332 KB |
Output is correct |
14 |
Correct |
16 ms |
332 KB |
Output is correct |
15 |
Correct |
14 ms |
424 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
6 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
5 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
280 KB |
Output is correct |
24 |
Runtime error |
0 ms |
332 KB |
Execution killed with signal 8 |
25 |
Halted |
0 ms |
0 KB |
- |