Cod sursa(job #1985320)

Utilizator emyll96Constantinescu Emil emyll96 Data 27 mai 2017 14:25:33
Problema Twoton Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.97 kb
#include <stdio.h>

int n,i;
int a[1000024];
int sum[1000024];
int count = 0,min;
int sumtotal;
int main()
{
	FILE *fin = fopen("twoton.in", "r");
	FILE *fout = fopen("twoton.out", "w");
	fscanf(fin, "%d", &n);
	for ( i = 0; i < n; ++i)
	{
		fscanf(fin, "%d", &a[i]);
	}
	for (i = n - 1; i >= 0; i--)
	{
		if (i == n - 1)
		{
			min = a[i];
			sum[i] = 1;
			sumtotal += 1;
			if (sumtotal >= 19997) {
				sumtotal -= 19997;
			}
		}
		else
		{
			if (a[i] < min)
			{
				min = a[i];
				sumtotal += 1;
				if (sumtotal >= 19997) {
					sumtotal -= 19997;
				}
				sum[i] =1; 
			}
			else
			{
				sum[i] = sumtotal+ 1;
				if (sum[i] >= 19997) {
					sum[i] -= 19997;
				}
				sumtotal += sum[i];
				if (sumtotal >= 19997) {
					sumtotal -= 19997;
				}
			}
		}
	}
	for (i = 0; i < n; i++)
	{
		count += sum[i];
		if (count >= 19997) {
			count -= 19997;
		}

	}
	fprintf(fout, "%d", count);
	fclose(fin);
	fclose(fout);
}