답안 #211640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211640 2020-03-20T21:23:41 Z MetB Calvinball championship (CEOI15_teams) C++14
100 / 100
225 ms 736 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
 
#define N 2000001
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1e18, MOD = 1e6 + 7, MOD2 = 1e6 + 3;

ll ans = 1, d[10001][2], a[N], n, mx[N];

int main () {
	cin >> n;

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

	for (int i = 0; i < n; i++) {
		d[i][0] = 1;
	}

	for (int i = n - 1; i >= 0; i--) {
		int k = ((n - i) & 1);
		
		for (int j = 0; j <= n; j++) {
			d[j][k] = (j * d[j][!k] + d[j+1][!k]) % MOD;
		}
		
		ans = (ans + (a[i] - 1) * d[i ? mx[i-1] : 0LL][!k]) % MOD;
	}

	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 215 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 512 KB Output is correct
2 Correct 58 ms 512 KB Output is correct
3 Correct 59 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 724 KB Output is correct
2 Correct 220 ms 632 KB Output is correct
3 Correct 218 ms 640 KB Output is correct