void sort(unsigned *a, int n)
{
unsigned *b=new unsigned[n];
unsigned *ptr0[256],*ptr8[256],*ptr16[256],*ptr24[256];
unsigned cnt0[256], cnt8[256], cnt16[256], cnt24[256];
unsigned *p;
for (int i = 0; i < 256; ++i)
{
cnt0[i] = 0;
cnt8[i] = 0;
cnt16[i] = 0;
cnt24[i] = 0;
}
for (int i = 0; i < n;)
{
++cnt0[a[i] & 255], ++cnt8[a[i] >> 8 & 255], ++cnt16[a[i] >> 16 & 255], ++cnt24[a[i] >> 24], ++i;
++cnt0[a[i] & 255], ++cnt8[a[i] >> 8 & 255], ++cnt16[a[i] >> 16 & 255], ++cnt24[a[i] >> 24], ++i;
++cnt0[a[i] & 255], ++cnt8[a[i] >> 8 & 255], ++cnt16[a[i] >> 16 & 255], ++cnt24[a[i] >> 24], ++i;
++cnt0[a[i] & 255], ++cnt8[a[i] >> 8 & 255], ++cnt16[a[i] >> 16 & 255], ++cnt24[a[i] >> 24], ++i;
}
ptr0[0]=b-1,ptr8[0]=a-1,ptr16[0]=b-1,ptr24[0]=a-1;
for (int i = 1; i < 256; ++i){
ptr0[i] = ptr0[i-1]+cnt0[i-1];
ptr8[i] = ptr8[i-1]+cnt8[i-1];
ptr16[i] = ptr16[i-1]+cnt16[i-1];
ptr24[i] = ptr24[i-1]+cnt24[i-1];
}
#define countingSort(a,k) \
for (int i = 0; i < n; i += 4){\
*++ptr##k[p[0] & 255] = p[0];\
*++ptr##k[p[1] & 255] = p[1];\
*++ptr##k[p[2] & 255] = p[2];\
*++ptr##k[p[3] & 255] = p[3];\
}
countingSort(a,0);
countingSort(b,8);
countingSort(a,16);
countingSort(b,24);
delete[] b;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 344.73 us | 420 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #2 | 331.235 ms | 381 MB + 508 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #3 | 662.467 ms | 762 MB + 992 KB | Runtime Error | Score: 0 | 显示更多 |