提交记录 27814
提交时间 |
评测时间 |
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;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.133 ms | 800 KB | Accepted | Score: 34 | 显示更多 |
Testcase #2 | 1.22 s | 762 MB + 984 KB | Accepted | Score: 33 | 显示更多 |
Testcase #3 | 2.44 s | 1525 MB + 920 KB | Accepted | Score: 33 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2025-04-05 13:47:33 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠