Cod sursa(job #466974)

Utilizator andrei.dAndrei Diaconeasa andrei.d Data 28 iunie 2010 10:16:14
Problema Pod Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2010, clasele X-XII, Ziua 2 Marime 1.58 kb
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

#define file_in "pod.in"
#define file_out "pod.out"

#define nmax 1010

int n,m,k;
int rez;
int g[nmax];
int v[10100001];
int inv[10000];

void citire()
{
    freopen(file_in,"r",stdin);
    freopen(file_out,"w",stdout);

    scanf("%d %d %d", &n, &m, &k);
    for (int i=1;i<=m;++i)
         scanf("%d", &g[i]);

}

#define mod 9901

int put(int a, int b)
{
    int t;
    if (b==0)
    return 1;
    t=put(a,b>>1);
    t=(t*t)%mod;
    if (b&1)
    t=(t*a)%mod;
    return t;
}

int comb(int x, int y)
{
    int i,t=1;
    for (i=x-y+1;i<=x;++i)
         t=(t*i)%mod;
    for (i=2;i<=y;++i)
         t=(t*inv[i])%mod;
    return t;
}


void solve()
{
    int i,x,y,j;
    for (i=1;i<mod;++i)
         inv[i]=put(i,mod-2);


     if (m==0)
     {
         //combinari de n-k+1 luate de cate 2 sper
         x=n-k+1;
         y=2;
         printf("%d\n", comb(x,y));
         exit(0);
     }



     for (i=1;i<=m;++i)
          v[g[i]]=1;

     if (v[1]==1 && v[k]==1)
     {
         printf("0\n");
         exit(0);
     }

     i=1;
     rez=0;
     while(i<=n)
     {
        while(v[i]==1) i++;
        j=i;
        while(v[j]==0 && j<=n) j++;
        x=j-i-1;
        //printf("%d\n", x);
        if (x>=k)
            rez=(rez+comb(x,2))%mod;
        i=j;
     }
     printf("%d", rez);

}

int main()
{
    citire();
    solve();

    fclose(stdin);
    fclose(stdout);

    return 0;
}