Submission #81971

# Submission time Handle Problem Language Result Execution time Memory
81971 2018-10-28T09:26:17 Z Saboon Calvinball championship (CEOI15_teams) C++14
100 / 100
216 ms 1240 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 1e4 + 10;
const int mod = 1e6 + 7;

ll pd[maxn], dp[3][maxn], par[maxn], a[maxn];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		par[i] = max (par[i - 1], a[i]);
	}

	for (int i = 1; i <= n; i++)
		dp[0][i] = 1;
	pd[0] = 1;
	for (int i = 1; i <= n; i++) {
		int p = i % 2;
		for (int j = 1; j <= n; j++) {
			dp[p][j] = (1ll * j * dp[p^1][j] + dp[p^1][j + 1]) % mod;
		}
		pd[i] = dp[p][par[n - i - 1]];
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = (ans + 1ll * (a[i] - 1) * pd[n - i] % mod);
	}
	cout << (ans + 1) % mod << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 660 KB Output is correct
2 Correct 2 ms 660 KB Output is correct
3 Correct 2 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 660 KB Output is correct
2 Correct 2 ms 660 KB Output is correct
3 Correct 2 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 660 KB Output is correct
2 Correct 2 ms 660 KB Output is correct
3 Correct 3 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 660 KB Output is correct
2 Correct 3 ms 660 KB Output is correct
3 Correct 3 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 660 KB Output is correct
2 Correct 4 ms 660 KB Output is correct
3 Correct 4 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1148 KB Output is correct
2 Correct 56 ms 1148 KB Output is correct
3 Correct 62 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 1180 KB Output is correct
2 Correct 214 ms 1180 KB Output is correct
3 Correct 216 ms 1240 KB Output is correct