提交记录 9650
提交时间 |
评测时间 |
2019-06-25 08:01:08 |
2020-08-01 01:45:00 |
#include <fstream>
#include <iostream>
using namespace std;
inline unsigned ceil_div(unsigned const &u, unsigned const &v)
{
return (u - 1) / v + 1;
}
inline void radix_sort(unsigned *&data, unsigned const &len, unsigned const &base)
{
const unsigned &chunk_num = ceil_div(32, base), &chunk_size = 1u << base;
unsigned i, j, k, **cnt = new unsigned* [chunk_num], *temp = new unsigned[len];
for (i = 0; i < chunk_num; ++i)
cnt[i] = new unsigned[chunk_size]();
for (i = 0; i < len; ++i)
for (j = 0, k = data[i]; j < chunk_num; ++j, k >>= base)
++cnt[j][k & (chunk_size - 1)];
for (i = 0; i < chunk_num; ++i)
{
for (j = 1; j < chunk_size; ++j)
cnt[i][j] += cnt[i][j - 1];
for (j = 1; j <= len; ++j)
{
k = len - j;
temp[--cnt[i][(data[k] >> (base * i)) & (chunk_size - 1)]] = data[k];
}
swap(data, temp);
}
for (i = 0; i < chunk_num; ++i)
delete[]cnt[i];
delete[]cnt;
delete[]temp;
}
void sort(unsigned *a, int n) {
radix_sort(a, n, 8);
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 928.088 ms | 762 MB + 1004 KB | Accepted | Score: 100 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-24 00:33:14 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠