Cod sursa(job #1220756)

Utilizator diana97Diana Ghinea diana97 Data 18 august 2014 14:47:42
Problema Grigo Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f ("grigo.in");
ofstream g ("grigo.out");

const int MOD = 1000003, MMAX = 100000 + 1;
int n, m;
int vizibil[MMAX];

long long solutie (int x) {
    if (!vizibil[x]) {
        if (x == n) return (n - 1);
        return solutie(x + 1) * (x - 1) % MOD;
    }
    if (x == n) return 1;
    return solutie (x + 1);
}

void citeste () {
    f >> n >> m;
    int x;
    for (int i = 1; i <= m; i++) f >> x, vizibil[x] = 1;
}

int main () {
    citeste();
    if (vizibil[1] == 0) g << 0 << '\n';
    else g << solutie(1) << '\n';
    return 0;
}