Cod sursa(job #1709823)

Utilizator UAICHePoBaMaHePoBaMa UAICHePoBaMa Data 28 mai 2016 14:02:32
Problema Twoton Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.74 kb
#include<iostream>
#include<fstream>
using namespace std;

ifstream f("twoton.in");
ofstream g("twoton.out");

int n;
int a[1000024];
int counts = 0;

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

int main() {
	f >> n;
	for (int i = 0; i < n; ++i) {
		f >> a[i];
	}
	int currentMin = a[n - 1];
	int result = 0;
	for (int i = n - 1; i >= 0; --i) {
		if (currentMin > a[i]) {
			result += 1;
			result %= 19997;
			currentMin = a[i];
		}
		else {
			result = 2 * result + 1;
			result %= 19997;
		}
	}
	wtf(0);
	g << result << endl << counts;
	f.close();
	g.close();
}