Cod sursa(job #2258453)

Utilizator FnZbZVrinceanu Radu FnZbZ Data 11 octombrie 2018 14:36:44
Problema 12-Perm Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

ifstream cin ("12perm.in");
ofstream cout ("12perm.out");

unsigned int N, result; bool Ok = true;
vector <int> numbers;

int main()
{
    cin >> N;
    cin.close();
    for(unsigned int index = 1; index <= N; index++)
        numbers.push_back(index);

    do
    {
        for(unsigned int index = 1; index < N && Ok; index++)
            if(abs(numbers.at(index-1) - numbers.at(index)) >= 3)
                Ok = false;
        result += Ok;
        Ok = true;
    }
    while(next_permutation(numbers.begin(), numbers.end()));

    cout << (result % 1048576);
    cout.close();
    return 0;
}