Cod sursa(job #2794263)

Utilizator ApostolIlieDanielApostol Daniel ApostolIlieDaniel Data 4 noiembrie 2021 16:19:03
Problema Congr Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using ll = long long;
#define dbg(x) cerr << #x << " " << x << "\n"

//#define HOME


int main() {
    freopen("congr.in", "r", stdin);
    freopen("congr.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int p;
    #ifdef HOME
        p = rng() % 299999 + 2;
        dbg(p);
    #else
        cin >> p;
    #endif // HOME
    vector <int> a, b;
    ll sum = 0;
    vector <int> v(2 * p);
    for (int i = 1; i <= 2 * p - 1; i++) {
        #ifdef HOME
            v[i] = rng() % p;
        #else
            cin >> v[i]; v[i] %= p;
        #endif // HOME
        if (i <= p)
            a.push_back(i), sum += v[i];
        else
            b.push_back(i);
    }
    sum %= p;
    #ifdef HOME
    int op = 0;
    #endif // HOME
    while (sum != 0) {
        int ai = rng() % p, bi = rng() % (p - 1);
        sum -= v[a[ai]];
        if (sum < 0) sum += p;
        swap(a[ai], b[bi]);
        sum += v[a[ai]];
        if (sum >= p) sum -= p;
        #ifdef HOME
            op++;
        #endif // HOME
    }
    #ifdef HOME
        dbg(op);
    #endif // HOME

    for (int x : a)
        cout << x << " ";
    cout << "\n";
    return 0;
}