Submission #429795

# Submission time Handle Problem Language Result Execution time Memory
429795 2021-06-16T09:36:39 Z dolphingarlic MalnaRISC (COI21_malnarisc) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

int ord[201];
vector<pair<int, int>> swaps[51];

void merge(int l, int sz, bool descending, int level) {
    int step = sz / 2;
    while (step) {
        for (int i = 0; i < sz; i += 2 * step) {
            for (int j = i + l; j < i + l + step; j++) {
                swaps[level].push_back({ord[j], ord[j + step]});
                if (descending) swap(ord[j], ord[j + step]);
            }
        }
        step >>= 1;
        level++;
    }
}

int main() {
    int n, block;
    scanf("%d", &n);
    iota(ord + 1, ord + 2 * n + 1, 1);
    for (block = 1; (1 << block - 1) < n; block++) {
        for (int i = 1; i <= n; i += 1 << block + 1) {
            int level = block * (block - 1) / 2;
            merge(i, 1 << block, false, level);
            if (i + (1 << block) <= n)
                merge(i + (1 << block), 1 << block, true, level);
        }
    }
    printf("%d\n", block * (block - 1) / 2);
    for (int i = 0; i < block * (block - 1) / 2; i++) {
        for (pair<int, int> j : swaps[i]) if (j.first <= n && j.second <= n)
            printf("CMPSWP R%d R%d ", j.first, j.second);
        printf("\n");
    }
    return 0;
}

Compilation message

malnarisc.cpp: In function 'int main()':
malnarisc.cpp:25:33: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   25 |     for (block = 1; (1 << block - 1) < n; block++) {
      |                           ~~~~~~^~~
malnarisc.cpp:26:49: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   26 |         for (int i = 1; i <= n; i += 1 << block + 1) {
      |                                           ~~~~~~^~~
malnarisc.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB not sorted
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB not sorted