Pagini recente » Cod sursa (job #2161794) | Cod sursa (job #1904223) | Cod sursa (job #3031280) | Cod sursa (job #1936470) | Cod sursa (job #475488)
Cod sursa(job #475488)
#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;
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);
}
sort(a.begin(), a.end());
for (int i = 1; i <= K; ++i)
{
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");
*/
}
for (int i = K + 1; i <= N; ++i)
{
//sumaLastK = sumaLastK - lastK.front();
if (a[pozitieCurenta] == i)
{
lastK.push_back(0);
pozitieCurenta++;
}
else
{
lastK.push_back(sumaLastK);
//sumaLastK >> 1;
//sumaLastK = sumaLastK * 2;
sumaLastK <<= 1;
}
sumaLastK = sumaLastK - lastK.front();
if (sumaLastK >= MOD)
sumaLastK = sumaLastK % MOD;
lastK.pop_front();
/*
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;
}