提交记录 27775


用户 题目 状态 得分 用时 内存 语言 代码长度
Izumi_Sagiri wc2017b1. 【WC2017】挑战-任务1 Wrong Answer 0 2.65 s 1562520 KB C++ 1.07 KB
提交时间 评测时间
2025-01-20 01:11:05 2025-01-20 01:11:11
#include <cstdint>
#include <cstring>
#include <algorithm>
void countingSort(unsigned *input, unsigned *output, int n, int bytePos) {
    unsigned count[256] = {0};
    // Count frequency of each byte value
    for (int i = 0; i < n; i++) {
        unsigned char byte = (input[i] >> (bytePos * 8)) & 0xFF;
        count[byte]++;
    }

    // Compute cumulative sum
    for (int i = 1; i < 256; i++) {
        count[i] += count[i - 1];
    }

    // Place elements into output array in sorted order
    for (int i = n - 1; i >= 0; i--) {
        unsigned char byte = (input[i] >> (bytePos * 8)) & 0xFF;
        output[count[byte] - 1] = input[i];
        count[byte]--;
    }
}
void radixSort(unsigned *a, unsigned *aux, int n) {
    for (int k = 0; k < 4; k++) {
        countingSort(a, aux, n, k);
        std::swap(a, aux);
    }
    // After 4 passes, the sorted array is in aux, so copy it back to a
    std::memcpy(a, aux, n * sizeof(unsigned));
}

void sort(unsigned *a, int n) {
    if (n <= 1) return;
    unsigned *aux = new unsigned[n];
    radixSort(a, aux, n);
    delete[] aux;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.191 ms800 KBWrong AnswerScore: 0

Testcase #21.326 s762 MB + 984 KBWrong AnswerScore: 0

Testcase #32.65 s1525 MB + 920 KBWrong AnswerScore: 0


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