Cod sursa(job #1709647)

Utilizator UCV_DUMITRU_ENACHE_MITROIUCV DUMITRU MITROI ENACHE UCV_DUMITRU_ENACHE_MITROI Data 28 mai 2016 13:14:28
Problema Twoton Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.76 kb
#include <iostream>
#include <limits.h>
#include <stdio.h>
using namespace std;

long n;
int a[1000024];
int count = 0;

long w[33000];
long wc[33000];

int wtf(int i){
    count ++;
    if (count >= 199997){
        count -= 199997;
    }
    if (i == n - 1){
        return a[i];
    }
    if (a[i] < wtf(i + 1)){
        return a[i];
    } else {
        return wtf(i + 1);
    }
}

int minus = 0;
int cnt = 0;

int gener(){
    wc[n-1] = 1;
    w[n-1] = a[n-1];
    for(long i = n - 2; i >= 0; i--){
        wc[i] += 1;

        if (wc[i] >= 199997){
            wc[i] -= 199997;
        }
        wc[i] += wc[i+1];
if (wc[i] >= 199997){
            wc[i] -= 199997;
        }
        if(a[i] >= w[i+1]){
//                cout << "true "  << i << endl;
            wc[i] += wc[i+1];
            w[i] = w[i+1];
        } else {
            w[i] = a[i];
        }
        if (wc[i] >= 199997){
            wc[i] -= 199997;
        }
    }
    return wc[0];
}


int wtf3(int i){
    count ++;
    if (count >= 199997){
        count -= 199997;
    }
    if (i == n - 1){
        return a[i];
    }
    count += wc[i+1];
//    wc[i] += wc[i+1];
    if (a[i] < w[i + 1]){
        w[i] = a[i];
        return a[i];
    } else {
        count += wc[i+1];
//        wc[i] += wc[i+1];
//        w[i] = w[i + 1];
        return w[i + 1];
    }
}

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

    fscanf(fin, "%d", &n);
    for( int i = 0; i < n; ++i){
        fscanf(fin, "%d", &a[i]);
    }

    long rez = gener();

//    wtf(0);
//cout << rez << " " << count;

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


    fclose(fin);
    fclose(fout);

    return 0;
}