Submission #784093

# Submission time Handle Problem Language Result Execution time Memory
784093 2023-07-15T16:29:14 Z NK_ Calvinball championship (CEOI15_teams) C++17
100 / 100
186 ms 1088 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define f first
#define s second
#define mp make_pair

using pi = pair<int, int>;
template<class T> using V = vector<T>;

const int MOD = int(1e6) + 7;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;
	V<int> A(N); for(auto& x : A) { cin >> x; --x; }

	V<array<int, 2>> dp(1, {1, 0}), ndp;

	for(int i = 1; i < N; i++) {
		ndp = V<array<int, 2>>(i + 1, {0, 0});

		for(int x = 0; x < i; x++) {
			// cout << i << " " << x << " -> " << dp[x][0] << " " << dp[x][1] << endl;
			if (dp[x][1]) {
				ndp[x + 1][1] += dp[x][1]; // increase max
				ndp[x][1] += ((x + 1) * 1LL * dp[x][1]) % MOD; // keep max

				if (ndp[x + 1][1] > MOD) ndp[x + 1][1] -= MOD;
				if (ndp[x][1] > MOD) ndp[x][1] -= MOD;
			}

			if (dp[x][0]) {
				int nmx = max(x, A[i]);
				ndp[nmx][0] += dp[x][0]; // keep equal
				ndp[x][1] += (A[i] * 1LL * dp[x][0]) % MOD; // go less

				if (ndp[nmx][0] > MOD) ndp[nmx][0] -= MOD;
				if (ndp[x][1] > MOD) ndp[x][1] -= MOD;
			}
		}

		dp.swap(ndp);
	}

	int ans = 0;
	for(int i = 0; i < N; i++) {
		ans += dp[i][0] + dp[i][1];
		ans %= MOD;
	}

	cout << ans << nl;


    return 0;
}


	
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 468 KB Output is correct
2 Correct 46 ms 532 KB Output is correct
3 Correct 47 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 716 KB Output is correct
2 Correct 186 ms 1088 KB Output is correct
3 Correct 185 ms 716 KB Output is correct