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 K 30
#define N 100
int ii[K][N], jj[K][N], nn[K], n, k;
void cmpswp(int i, int j) {
if (i < n && j < n)
ii[k][nn[k]] = i, jj[k][nn[k]] = j, nn[k]++;
}
void flush() {
if (nn[k])
k++;
}
int main() {
int n_, l_, l, l1, h, i;
scanf("%d", &n);
l_ = 0;
while (1 << l_ < n)
l_++;
n_ = 1 << l_;
for (l = 1; l <= l_; l++) {
for (i = 0; i < n_; i++)
if ((i & 1 << l - 1) == 0)
cmpswp(i, i ^ (1 << l) - 1);
flush();
for (l1 = l - 2; l1 >= 0; l1--) {
for (i = 0; i < n_; i++)
if ((i & 1 << l1) == 0)
cmpswp(i, i ^ (1 << l1));
flush();
}
}
printf("%d\n", k);
for (h = 0; h < k; h++) {
for (i = 0; i < nn[h]; i++)
printf("CMPSWP R%d R%d ", ii[h][i] + 1, jj[h][i] + 1);
printf("\n");
}
return 0;
}
Compilation message (stderr)
malnarisc.c: In function 'main':
malnarisc.c:28:20: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
28 | if ((i & 1 << l - 1) == 0)
| ~~^~~
malnarisc.c:29:28: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
29 | cmpswp(i, i ^ (1 << l) - 1);
| ~~~~~~~~~^~~
malnarisc.c:21:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |