Cod sursa(job #3327701)

Utilizator horatiu.avramAvram Popa Cristian Horatiu horatiu.avram Data 4 decembrie 2025 20:03:05
Problema Radix Sort Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include<bits/stdc++.h>
using namespace std;
const int MAXBITS=32;
const int BITS=8;
const int MAXN=1e7;
const int MAXM=256;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int v[MAXN+1],tmp[MAXN+1];
int f[MAXM];
int main() {
    int n,a,b,c;
    fin>>n>>a>>b>>c;
    v[0]=b;
    for(int i=1; i<n; i++) {
        v[i]=((long long)a*v[i-1]+b)%c;
    }
    int nr;
    for(int j=0; j<MAXBITS/BITS; j++) {
        for(int i=0; i<n; i++) {
            f[(v[i]>>(j*BITS))&(MAXM-1)]++;
        }
        for(int i=1; i<MAXM; i++) {
            f[i]+=f[i-1];
        }
        for(int i=n-1; i>=0; i--) {
            tmp[--f[(v[i]>>(j*BITS))&(MAXM-1)]]=v[i];
        }
        for(int i=0; i<n; i++) {
            v[i]=tmp[i];
        }
        for(int i=0; i<MAXM; i++) {
            f[i]=0;
        }
    }
    for(int i=0; i<n; i+=10) {
        fout<<v[i]<<' ';
    }
    return 0;
}