Submission #74687

# Submission time Handle Problem Language Result Execution time Memory
74687 2018-09-06T14:22:48 Z shoemakerjo Calvinball championship (CEOI15_teams) C++14
100 / 100
215 ms 1168 KB
#include <bits/stdc++.h>

using namespace std;

const int mod = 1000007;
#define maxn 10010

int dp[2][maxn];

int n;
int nums[maxn];
int maxbef[maxn];

int main() {
	fill(dp[0], dp[0]+maxn, 1);
	fill(dp[1], dp[1]+maxn, 1);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int cur = 0, prev = 1;
	cin >> n;
	//going to do 1-indexed
	for (int i = 1; i <= n; i++) {
		cin >> nums[i];
	}
	for (int i = 1; i <= n; i++) {
		maxbef[i] = max(maxbef[i-1],  nums[i-1]);
	}
	int ans = 0;
	for (int i = n; i >= 1; i--, swap(prev, cur)) {
		for (int j = 1; j <= i; j++) {
			//this whole thing is free range
			dp[cur][j] = (j*1LL*dp[prev][j])%mod;
			dp[cur][j] = (dp[cur][j] + dp[prev][j+1])%mod;
		}
		int val = 0;
		val = (val + (nums[i]-1)*1LL*dp[prev][maxbef[i]])%mod;
		ans = (ans+val)%mod;
	}
	cout << ans+1 << endl; //think we want the plus 1


}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
4 Correct 2 ms 644 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 644 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 2 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 844 KB Output is correct
3 Correct 2 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 844 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 844 KB Output is correct
2 Correct 4 ms 844 KB Output is correct
3 Correct 5 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 984 KB Output is correct
2 Correct 58 ms 1028 KB Output is correct
3 Correct 55 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 1028 KB Output is correct
2 Correct 214 ms 1168 KB Output is correct
3 Correct 212 ms 1168 KB Output is correct