Cod sursa(job #1709478)

Utilizator UTCN_rachetaUTCN Pocol Rogoz Oltean UTCN_racheta Data 28 mai 2016 12:29:24
Problema Twoton Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.95 kb
#include <stdio.h>

int n;
int a[1000024], w[1000024];
int count = 0;

static int wtf(int i)
{
    printf ("%d ", 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_iterativ()
{
    int i, c;
    w[n-1] = 1;
    c = a[n-1];
    for(i=n-2; i>=0; i--)
    {
        if(a[i] < c)
        {
            w[i] = (1 + w[i+1]) % 19997;
            c = a[i];
        }
        else
        {
            w[i] = (1 + 2*w[i+1]) % 19997;
        }
    }
}

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(0);
  wtf_iterativ();
  fprintf(fout, "%d\n", w[0]);
  fclose(fin);
  fclose(fout);
}