Cod sursa(job #1935511)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 22 martie 2017 14:37:11
Problema Twoton Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.73 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);
}