답안 #67899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67899 2018-08-15T12:31:35 Z polyfish Calvinball championship (CEOI15_teams) C++14
100 / 100
585 ms 972 KB
//I love armpit fetish

#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

const int MAX_N = 10002;
const int MOD = 1000007;

int n, a[MAX_N], max_a[MAX_N], f[2][MAX_N];

void enter() {
	cin >> n;
	for (int i=1; i<=n; ++i)
		cin >> a[i];
}

void solve() {
	int res = 1, cur = 0;
	for (int last=1; last<=n; ++last)
		f[cur][last] = 1;
	for (int i=1; i<=n; ++i)
		max_a[i] = max(max_a[i-1], a[i]);
	for (int i=n; i>=1; --i) {
		cur ^= 1;
		for (int nGroup=1; nGroup<i; ++nGroup) {
			f[cur][nGroup] = (f[cur^1][nGroup+1] + 1LL * f[cur^1][nGroup] * nGroup % MOD) % MOD;
		}
		for (int j=1; j<a[i]; ++j)
			res = (res + f[cur^1][max(max_a[i-1], j)]) % MOD;
	}
	cout << res;
}

int main() {
	//#define OFFLINE_JUDGE doraemon
	#ifdef OFFLINE_JUDGE
		freopen(FILE_NAME".inp", "r", stdin);
		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);
	enter();
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 3 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 764 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 8 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 544 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 796 KB Output is correct
2 Correct 57 ms 796 KB Output is correct
3 Correct 141 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 888 KB Output is correct
2 Correct 278 ms 972 KB Output is correct
3 Correct 585 ms 972 KB Output is correct