Submission #429861

# Submission time Handle Problem Language Result Execution time Memory
429861 2021-06-16T10:05:30 Z dolphingarlic MalnaRISC (COI21_malnarisc) C++14
100 / 100
1 ms 204 KB
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int p2 = 1, blocks = 0;
    while (p2 < n) p2 <<= 1, blocks++;
    printf("%d\n", blocks * (blocks + 1) / 2);
    for (int p = 1; p < p2; p <<= 1) {
        for (int k = p; k; k >>= 1) {
            for (int j = k % p; j < p2 - k; j += 2 * k) {
                for (int i = 0; i < k && i + j + k < n; i++) {
                    if ((i + j) / (2 * p) == (i + j + k) / (2 * p)) {
                        printf("CMPSWP R%d R%d ", i + j + 1, i + j + k + 1);
                    }
                }
            }
            printf("\n");
        }
    }
    return 0;
}

Compilation message

malnarisc.cpp: In function 'int main()':
malnarisc.cpp:5:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct