Cod sursa(job #2562268)

Utilizator Dobricean_IoanDobricean Ionut Dobricean_Ioan Data 29 februarie 2020 13:12:20
Problema Congr Scor 80
Compilator cpp-64 Status done
Runda sim11_2 Marime 1.72 kb
#include <fstream>
#include <stdlib.h>
#include <cstdio>
using namespace std;


ofstream fout ("congr.out");

const long long MAXN = 600001;
pair <long long,long long> a[MAXN];
long long n,p,sum;

#include <stdio.h>

#include <ctype.h>



class InParser {

private:

FILE *fin;

char *buff;

int sp;



char read_ch() {

    ++sp;

    if (sp == 4096) {

        sp = 0;

        fread(buff, 1, 4096, fin);

    }

    return buff[sp];

}



public:

InParser(const char* nume) {

    fin = fopen(nume, "r");

    buff = new char[4096]();

    sp = 4095;

}



InParser& operator >> (int &n) {

    char c;

    while (!isdigit(c = read_ch()) && c != '-');

    int sgn = 1;

    if (c == '-') {

        n = 0;

        sgn = -1;

    } else {

        n = c - '0';

    }

    while (isdigit(c = read_ch())) {

        n = 10 * n + c - '0';

    }

    n *= sgn;

    return *this;

}



InParser& operator >> (long long &n) {

    char c;

    n = 0;

    while (!isdigit(c = read_ch()) && c != '-');

    long long sgn = 1;

    if (c == '-') {

        n = 0;

        sgn = -1;

    } else {

        n = c - '0';

    }

    while (isdigit(c = read_ch())) {

        n = 10 * n + c - '0';

    }

    n *= sgn;

    return *this;

}

};
InParser fin ("congr.in");


int main() {
    fin >> p;
    n = 2*p-1;

    for(long long i = 1; i <= n; ++i) {
        fin >> a[i].first,a[i].second = i;
        a[i].first %= p;
        if(i <= p)
            sum += a[i].first;
    }
    srand(unsigned(time(0)));
    while( sum % p) {

        int p1 = rand() % p + 1;
        int p2 = rand() % (p-1) + p+1;
        sum += (-a[p1].first + a[p2].first+p) % p;
        swap(a[p1],a[p2]);
    }
    for ( int i = 1; i <= p; ++i)
    fout << a[i].second << " ";


}