Cod sursa(job #1709209)

Utilizator UNIBUC_Costan_Iordache_MagureanuGangster Teddy Bears Trio UNIBUC_Costan_Iordache_Magureanu Data 28 mai 2016 11:17:26
Problema Twoton Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.47 kb
#include <cstdio>
#include<utility>
#include<stack>

int n;
int a[1000024];
int count[1000024];
int ret[1000024];

//stack<pair<int,int> > stk;

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

void wtf(){
    int i;

    ret[n-1]=a[n-1];
    count[n-1]=1;

    for(i=n-2;i>=0;i--){
        count[i]=1+count[i+1];
        if (a[i]<ret[i+1]){
            ret[i]=a[i];
        }
        else {
            ret[i]=ret[i+1];
            count[i]+=count[i+1];
        }
        if (count[i] >= 19997) {
            count[i] -= 19997;
        }
        if (count[i] >= 19997) {
            count[i] -= 19997;
        }
    }
}

//int ret;

/*int wtf(int i)
{
    stk.push_back(make_pair(i,0));
    while(!stk.empty()){
        count++;
        if (count >= 19997) {
            count -= 19997;
        }
        if (stk.top().first == n - 1) {
            ret=a[stk.top().first];
            stk.pop();
        }
        else
        if (a[i] < wtf(i + 1)) {
            ret=a[stk.top()];
            stk.pop();
        }
        else {
            return wtf(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]);
  }
  wtf();
  fprintf(fout, "%d\n", count[0]);
  fclose(fin);
  fclose(fout);
}