提交记录 9650


用户 题目 状态 得分 用时 内存 语言 代码长度
webmaster 1001. 测测你的排序 Accepted 100 928.088 ms 781292 KB C++ 1.07 KB
提交时间 评测时间
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);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1928.088 ms762 MB + 1004 KBAcceptedScore: 100


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