Cod sursa(job #1710134)

Utilizator bciobanuBogdan Ciobanu bciobanu Data 28 mai 2016 16:09:01
Problema Twoton Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

constexpr int MAX_N = 100000;
constexpr int MOD = 19997;

int v[MAX_N];

int main() {
  ifstream fin("twoton.in");
  ofstream fout("twoton.out");
  fin.tie(0);
  ios_base::sync_with_stdio(0);

  int n; fin >> n;

  for (int i = 0; i < n; i += 1) {
    fin >> v[i];
  }
  fin.close();

  int last = 1, best = v[n - 1];

  for (int i = n - 2; i >= 0; i -= 1) {
    if (v[i] < best) {
      last += 1;
      best = v[i];
    } else {
      last = (last + last + 1);
      last -= (MOD & -(last >= MOD));
    }
    last -= (MOD & -(last >= MOD));
  }

  fout << last << '\n';
  fout.close();

  return 0;
}