提交记录 39951


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 wc2017b1. 【WC2017】挑战-任务1 Accepted 100 2.119 s 1562528 KB C++ 1.28 KB
提交时间 评测时间
2026-08-17 03:28:57 2026-08-17 03:29:03
#include <string.h>
typedef unsigned int u32;

static u32 b[200000000];
static u32 cnt[1024];

void sort(unsigned *a, int n) {
  u32 *c0 = cnt, *c1 = cnt + 256, *c2 = cnt + 512, *c3 = cnt + 768;
  u32 *t = b;

  // count byte 0 only (1 increment/element)
  memset(c0, 0, 256*4);
  for (int i = 0; i < n; i++) c0[a[i] & 255]++;
  u32 s = 0;
  for (int i = 0; i < 256; i++) { u32 v = c0[i]; c0[i] = s; s += v; }

  // pass 1: scatter byte 0 (a->t), count byte 1
  memset(c1, 0, 256*4);
  for (int i = 0; i < n; i++) {
    u32 x = a[i];
    t[c0[x & 255]++] = x;
    c1[(x >> 8) & 255]++;
  }
  s = 0;
  for (int i = 0; i < 256; i++) { u32 v = c1[i]; c1[i] = s; s += v; }

  // pass 2: scatter byte 1 (t->a), count byte 2
  memset(c2, 0, 256*4);
  for (int i = 0; i < n; i++) {
    u32 x = t[i];
    a[c1[(x >> 8) & 255]++] = x;
    c2[(x >> 16) & 255]++;
  }
  s = 0;
  for (int i = 0; i < 256; i++) { u32 v = c2[i]; c2[i] = s; s += v; }

  // pass 3: scatter byte 2 (a->t), count byte 3
  memset(c3, 0, 256*4);
  for (int i = 0; i < n; i++) {
    u32 x = a[i];
    t[c2[(x >> 16) & 255]++] = x;
    c3[x >> 24]++;
  }
  s = 0;
  for (int i = 0; i < 256; i++) { u32 v = c3[i]; c3[i] = s; s += v; }

  // pass 4: scatter byte 3 (t->a)
  for (int i = 0; i < n; i++) {
    u32 x = t[i];
    a[c3[x >> 24]++] = x;
  }
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.002 ms812 KBAcceptedScore: 34

Testcase #21.059 s762 MB + 992 KBAcceptedScore: 33

Testcase #32.119 s1525 MB + 928 KBAcceptedScore: 33


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-03 22:13:20 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠