Submission #429741

# Submission time Handle Problem Language Result Execution time Memory
429741 2021-06-16T09:01:59 Z dolphingarlic MalnaRISC (COI21_malnarisc) C++14
0 / 100
2 ms 340 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

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

void merge(int l, int sz, int n, 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 + step <= n; 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 + n + 1, 1);
    for (block = 1; (1 << block - 1) < n; block++) {
        for (int i = 1; i <= n; i += 1 << block + 1) {
            merge(i, 1 << block, n, false, block * (block - 1) / 2);
            merge(i + (1 << block), 1 << block, n, true, block * (block - 1) / 2);
        }
    }
    printf("%d\n", block * (block - 1) / 2);
    for (int i = 0; i < block * (block - 1) / 2; i++) {
        for (pair<int, int> j : swaps[i])
            printf("CMPSWP R%d R%d ", j.first, j.second);
        printf("\n");
    }
    return 0;
}

Compilation message

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