Cod sursa(job #2100832)

Utilizator miguelMihail Lavric miguel Data 6 ianuarie 2018 13:49:33
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define pb push_back
const ll mod = 1e9 + 7;
int n, a, b, c, y, k;
vector < vector <int>> v(1001);

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    ifstream fin("radixsort.in");
    ofstream fout("radixsort.out");
    fin>>n>>a>>b>>c;
    int x=INT_MAX/1000;
    v[b/x].pb(b); ll y=b*1LL;
    for(int i=1; i<n; i++){v[((y*a+b)%c)/x].pb((y*a+b)%c); y=(y*a+b)%c;}
    for(int i=0; i<1001; i++) sort(v[i].begin(), v[i].end());
    for(int i=0; i<1001; i++){
            for(int j=0; j<v[i].sz; j++){
                if(k%10==0){fout<<v[i][j]<<" "; } k++;}}
}