This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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]--;
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |