提交记录 27814


用户 题目 状态 得分 用时 内存 语言 代码长度
Izumi_Sagiri wc2017b1. 【WC2017】挑战-任务1 Accepted 100 2.44 s 1562520 KB C++17 1.03 KB
提交时间 评测时间
2025-01-27 13:09:09 2025-01-27 13:09:15
#include <algorithm> // For std::swap

void sort(unsigned *a, int n) {
    const int num_shifts = 4;
    const int bucket_count = 256;

    unsigned *temp = new unsigned[n];
    unsigned *input = a;
    unsigned *output = temp;

    for (int shift = 0; shift < num_shifts; ++shift) {
        size_t count[bucket_count] = {0};

        // Count the occurrences of each digit
        for (int i = 0; i < n; ++i) {
            unsigned digit = (input[i] >> (shift * 8)) & 0xFF;
            ++count[digit];
        }

        // Calculate prefix sums to determine positions
        size_t prefix[bucket_count] = {0};
        for (int i = 1; i < bucket_count; ++i) {
            prefix[i] = prefix[i - 1] + count[i - 1];
        }

        // Distribute elements into the output array
        for (int i = 0; i < n; ++i) {
            unsigned digit = (input[i] >> (shift * 8)) & 0xFF;
            output[prefix[digit]++] = input[i];
        }

        // Swap input and output for the next pass
        std::swap(input, output);
    }

    delete[] temp;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.133 ms800 KBAcceptedScore: 34

Testcase #21.22 s762 MB + 984 KBAcceptedScore: 33

Testcase #32.44 s1525 MB + 920 KBAcceptedScore: 33


Judge Duck Online | 评测鸭在线
Server Time: 2025-04-05 13:47:33 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠