提交记录 27334


用户 题目 状态 得分 用时 内存 语言 代码长度
recadend8 wc2017b1. 【WC2017】挑战-任务1 Accepted 100 2.162 s 1562524 KB C++17 1.15 KB
提交时间 评测时间
2024-11-13 02:38:39 2024-11-13 02:38:45
#include <array>

void sort(unsigned* a, int n) {
    constexpr int BASE_WIDTH = 8;
    constexpr unsigned BASE = 1 << BASE_WIDTH;

    auto cursors = std::array<std::array<int, BASE>, 4>();
    for (int i = 0; i < n; i++) {
        cursors[0][a[i] & (BASE - 1)]++;
        cursors[1][(a[i] >> BASE_WIDTH) & (BASE - 1)]++;
        cursors[2][(a[i] >> (2 * BASE_WIDTH)) & (BASE - 1)]++;
        cursors[3][a[i] >> (3 * BASE_WIDTH)]++;
    }

    for (int iter = 0; iter < 4; iter++) {
        int prefix_offset = 0;
        for (unsigned v = 0; v < BASE; v++) {
            std::swap(prefix_offset, cursors[iter][v]);
            prefix_offset += cursors[iter][v];
        }
    }

    auto buffer = new unsigned[n];

    for (int i = 0; i < n; i++) {
        buffer[cursors[0][a[i] & (BASE - 1)]++] = a[i];
    }
    for (int i = 0; i < n; i++) {
        a[cursors[1][(buffer[i] >> BASE_WIDTH) & (BASE - 1)]++] = buffer[i];
    }
    for (int i = 0; i < n; i++) {
        buffer[cursors[2][(a[i] >> (2 * BASE_WIDTH)) & (BASE - 1)]++] = a[i];
    }
    for (int i = 0; i < n; i++) {
        a[cursors[3][buffer[i] >> (3 * BASE_WIDTH)]++] = buffer[i];
    }

    delete[] buffer;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.011 ms804 KBAcceptedScore: 34

Testcase #21.08 s762 MB + 988 KBAcceptedScore: 33

Testcase #32.162 s1525 MB + 924 KBAcceptedScore: 33


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 05:48:34 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠