Cod sursa(job #2324163)

Utilizator NOSCOPEPROKENDYMACHEAMACUMVREAU NOSCOPEPROKENDY Data 20 ianuarie 2019 12:34:26
Problema Twoton Scor 100
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.84 kb

#include <cstdio>

#include <algorithm>



using namespace std;



FILE *fin = fopen("twoton.in", "r"), *fout = fopen("twoton.out", "w");



const int mod = 19997;

const int nmax = 100000;

const int inf = (1 << 30);



int n;

int a[nmax + 1], creste[nmax + 1];

int cnt = 0;



int main()

{

    fscanf(fin, "%d", &n);



    for (int i = 0; i < n; ++ i) {

        fscanf(fin, "%d", &a[ i ]);

    }



    int mn = inf;

    for (int i = n - 1; i >= 0; -- i) {

        if (a[ i ] < mn) {

            creste[ i ] = creste[i + 1] + 1;

        } else {

            creste[ i ] = 2 * creste[i + 1] + 1;

        }

        creste[ i ] %= mod;

        mn = min(mn, a[ i ]);

    }

    cnt = creste[ 0 ];



    fprintf(fout, "%d\n", cnt);

    fclose(fin);

    fclose(fout);

}