Cod sursa(job #1774396)

Utilizator R4DIC4LTeodorescu Oana Maria R4DIC4L Data 8 octombrie 2016 21:33:33
Problema Twoton Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.65 kb
#include <iostream>
#include <cstdio>
#define Nmax 1000024
#define MOD 19997
using namespace std;
 
int T;
int a[Nmax];
 
 
int main() {
    freopen("twoton.in", "r", stdin);
    freopen("twoton.out", "w", stdout);
 
    scanf("%d", &T);
 
    long long sol = 0;
 
    for(int i = 0; i < T; ++i){
        scanf("%d", &a[i]);
    }
 
    long long last = 1;
    int lastPos = T-1;
    for(int i = T-2; i >= 0; --i) {
        if(a[i] > a[lastPos]) {
            last = (1 + 2 * last) % MOD;
        } else {
            last = (last + 1) % MOD;
            lastPos = i;
        }
    }
 
    printf("%lld\n", last);
 
    return 0;
}