Submission #88721

# Submission time Handle Problem Language Result Execution time Memory
88721 2018-12-07T22:48:40 Z jasony123123 Zoltan (COCI16_zoltan) C++11
42 / 140
1000 ms 15108 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll PRIME = 105943LL;
const int INF = 1e6;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
	/* online submission */
#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/*************************COCI 16-17 R3 #5*************************/

const int MAXN = 200000;
int N;
int A[MAXN];
pii incr[MAXN], dcr[MAXN]; // length, #

/*/?????*/
pii genBest() { // length of best, # ways
	pii best = { -1,-1 };
	FOR(i, 0, N) {
		pii temp = { dcr[i].first + incr[i].first - 1, dcr[i].second*incr[i].second };
		if (temp.first > best.first)
			best = temp;
		else if (temp.first == best.first)
			best.second += temp.second;
	}
	return best;
}

void calcIncr() {
	RFORE(i, N - 1, 0) {
		incr[i] = { 1, 1 };
		FOR(j, i + 1, N) if (A[i] < A[j]) {
			pii temp = { 1 + incr[j].first, incr[j].second };
			if (temp.first > incr[i].first)
				incr[i] = temp;
			else if (temp.first == incr[i].first)
				incr[i].second += temp.second;
		}
	}
}

void calcDcr() {
	RFORE(i, N - 1, 0) {
		dcr[i] = { 1, 1 };
		FOR(j, i + 1, N) if (A[i] > A[j]) {
			pii temp = { 1 + dcr[j].first, dcr[j].second };
			if (temp.first > dcr[i].first)
				dcr[i] = temp;
			else if (temp.first == dcr[i].first)
				dcr[i].second += temp.second;
		}
	}
}

void modd(ll &x) {
	x %= MOD;
}

ll pow(ll a, ll p) {
	ll ret = 1LL;
	while (p) {
		if (p & 1LL)
			ret *= a;
		a *= a;
		modd(ret);
		modd(a);
		p >>= 1;
	}
	return ret;
}

int main(void) {
	io();
	cin >> N;
	FOR(i, 0, N) cin >> A[i];
	calcIncr();
	calcDcr();
	pii best = genBest();
	cout << best.first << "\n";
	ll ways = best.second*pow(2, N - best.first);
	modd(ways);
	cout << ways << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Incorrect 6 ms 752 KB Output isn't correct
8 Incorrect 6 ms 764 KB Output isn't correct
9 Incorrect 6 ms 792 KB Output isn't correct
10 Incorrect 6 ms 820 KB Output isn't correct
11 Execution timed out 1076 ms 2872 KB Time limit exceeded
12 Execution timed out 1080 ms 4004 KB Time limit exceeded
13 Execution timed out 1086 ms 4852 KB Time limit exceeded
14 Execution timed out 1083 ms 6156 KB Time limit exceeded
15 Execution timed out 1084 ms 8120 KB Time limit exceeded
16 Execution timed out 1069 ms 10028 KB Time limit exceeded
17 Execution timed out 1081 ms 11456 KB Time limit exceeded
18 Execution timed out 1079 ms 12880 KB Time limit exceeded
19 Execution timed out 1079 ms 14072 KB Time limit exceeded
20 Execution timed out 1085 ms 15108 KB Time limit exceeded