Pagini recente » Cod sursa (job #1987682) | Cod sursa (job #845681) | Cod sursa (job #292383) | Cod sursa (job #1953285) | Cod sursa (job #475489)
Cod sursa(job #475489)
#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;
}