Cod sursa(job #475489)

Utilizator alex23alexandru andronache alex23 Data 7 august 2010 09:53:25
Problema Pod Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 3.28 kb
#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 9901;

deque<int> lastK;
vector<int> a;
int N, M, K, pozitieCurenta = 0, sumaLastK = 0;
int x1 = 0, x2 = 1;

FILE *f = fopen("pod.in", "r");
FILE *g = fopen("pod.out", "w");


deque<int>::iterator it;

int main()
{
    
    fscanf(f, "%d %d %d", &N, &M, &K);
    
    for (int i = 0; i < M; ++i)
    {
        int x;
        fscanf(f, "%d", &x);
        a.push_back(x);
        //if (x < K) x1 == 0;
        //if (x == K) x2 == 0;
    }
    
    sort(a.begin(), a.end());
    
    for (int i = 1; i < K; ++i)
    {
        if ((a[pozitieCurenta] == i) || x1)
        {
           lastK.push_back(0);
           if (a[pozitieCurenta] == i) pozitieCurenta++;
           x1 = 1;
        }
        else
        {
            lastK.push_back(1);
            //sumaLastK++;
        }
        /*
        if (a[pozitieCurenta] == i)
        {
           lastK.push_back(0);
           pozitieCurenta++;  
        }
        else
        {
           lastK.push_back(sumaLastK + 1);
           sumaLastK += sumaLastK + 1;
           if (sumaLastK >= MOD)
              sumaLastK = sumaLastK % MOD;
        }
        */
        /*
        for (it = lastK.begin(); it != lastK.end(); ++it)
        {
            printf("%d ", *it);
        }
        printf("%d ", sumaLastK);
        printf("\n");
        */
    }
    
    if (a[pozitieCurenta] == K)
    {
        if (lastK.back())
        {
            lastK.push_back(1);
        }
        else
        {
            lastK.push_back(0);
        }
        pozitieCurenta++;
        //printf("DDDDDDD\n");
    }
    else
    {
        if (lastK.back())
        {
            lastK.push_back(2);
        }
        else
        {
            lastK.push_back(1);
        }
    }
    /*
    for (it = lastK.begin(); it != lastK.end(); ++it)
        {
            printf("%d ", *it);
        }
        //printf("%d ", sumaLastK);
        printf("\n");
        */
    
    for (int i = K + 1; i <= N; ++i)
    {
        //printf("iiiii = %d\n", i);
        if (a[pozitieCurenta] == i)
        {
            lastK.push_back(0);
            pozitieCurenta++;
            lastK.pop_front();
            //printf("i = %d\n", i); 
        }
        else
        {
            lastK.push_back((lastK.front() + lastK.back()) % MOD);
            lastK.pop_front();
        }
        /*
        //sumaLastK = sumaLastK - lastK.front();
        if (a[pozitieCurenta] == i)
        {
            lastK.push_back(0);
            pozitieCurenta++;
        }
        else
        {
            lastK.push_back(sumaLastK);
            //sumaLastK = sumaLastK * 2;
            sumaLastK <<= 1;
        }
        sumaLastK = sumaLastK - lastK.front();
        lastK.pop_front();
        if (sumaLastK >= MOD)
              sumaLastK = sumaLastK % MOD;
              */
              /*
        for (it = lastK.begin(); it != lastK.end(); ++it)
        {
            printf("%d ", *it);
        }
        //printf("%d ", sumaLastK);
        printf("\n");
        */
    }
    
    fprintf(g, "%d", lastK.back());
    
    
    fclose(f);
    fclose(f);
    return 0;
}