Cod sursa(job #2134349)

Utilizator cella.florescuCella Florescu cella.florescu Data 17 februarie 2018 21:07:27
Problema 12-Perm Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;

const int MOD = (1 << 20) - 1;
const int QUEUEMOD = 3;

int dp[QUEUEMOD + 1] = {1, 2, 6, 12};

int main()
{
    int n;
    ifstream fin("12perm.in");
    fin >> n;
    fin.close();
    for (int i = 4, ind = 0; i < n; ++i, ind = ((ind + 1) & QUEUEMOD))
      dp[ind] = ((dp[(ind + 1) & QUEUEMOD] + dp[(ind + 3) & QUEUEMOD] + 2 * i - 2) % MOD);
    ofstream fout("12perm.out");
    fout << dp[(n - 1) & QUEUEMOD];
    fout.close();
    return 0;
}