Cod sursa(job #1709432)

Utilizator theboysUVT Talpau Craciun Ciobanu theboys Data 28 mai 2016 12:14:11
Problema Twoton Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.46 kb
#include <stdio.h>

#define CST 19997

int a[1001024];
int w[1001024];

int main(){
	
	freopen("twoton.in", "r", stdin);
	freopen("twoton.out", "w", stdout);
	
	int n, c_min;
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
	}
	
	w[n - 1] = 1; c_min = a[n - 1];
	for(int i = n - 2; i >= 0; --i){
		if(a[i] < c_min){
			c_min = a[i];
			w[i] = (1 + w[i + 1]) % CST;
		}else{
			w[i] = (1 + 2 * w[i + 1]) % CST;
		}
	}
	
	printf("%d", w[0]);
	
return 0;
}