Pagini recente » Cod sursa (job #1836460) | Cod sursa (job #2477434) | Cod sursa (job #3174212) | Cod sursa (job #811332) | Cod sursa (job #1709478)
#include <stdio.h>
int n;
int a[1000024], w[1000024];
int count = 0;
static int wtf(int i)
{
printf ("%d ", i);
count++;
if (count >= 19997) {
count -= 19997;
}
if (i == n - 1) {
return a[i];
}
if (a[i] < wtf(i + 1)) {
return a[i];
} else {
return wtf(i + 1);
}
}
void wtf_iterativ()
{
int i, c;
w[n-1] = 1;
c = a[n-1];
for(i=n-2; i>=0; i--)
{
if(a[i] < c)
{
w[i] = (1 + w[i+1]) % 19997;
c = a[i];
}
else
{
w[i] = (1 + 2*w[i+1]) % 19997;
}
}
}
int main()
{
FILE *fin = fopen("twoton.in", "r");
FILE *fout = fopen("twoton.out", "w");
fscanf(fin, "%d", &n);
for (int i = 0; i < n; ++i) {
fscanf(fin, "%d", &a[i]);
}
//wtf(0);
wtf_iterativ();
fprintf(fout, "%d\n", w[0]);
fclose(fin);
fclose(fout);
}