답안 #587974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587974 2022-07-02T15:23:01 Z Blagojce Calvinball championship (CEOI15_teams) C++11
100 / 100
259 ms 560 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int mxn = 10004;
const ll  mod =  1000007;

int a[mxn];
int n;

ll DP1[mxn];
ll DP2[mxn];


int main(){
	
	cin >> n;
	fr(i, 0, n){
		cin >> a[i];
	}
	int mx[n];
	
	int c = 0;
	fr(i, 0, n){
		c = max(c, a[i]);
		mx[i] = c;
	}
	ll ans = 1;
	fr(i, 0, n+1) DP1[i] = 1;
	for(int i = n-1; i >= 0; i --){
		int nxt = 1;
		if(i > 0) nxt = mx[i-1];
		
		ans += ((a[i]-1) * DP1[nxt]) % mod;
		ans %= mod;
		
		fr(j, 0, n+1){
			DP2[j] = (DP1[j+1] + j*DP1[j]) % mod;
		}
		fr(j, 0, n+1){
			DP1[j] = DP2[j];
		}
	}
	
	cout<<ans<<endl;
}



# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 240 KB Output is correct
2 Correct 2 ms 280 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 404 KB Output is correct
2 Correct 49 ms 340 KB Output is correct
3 Correct 49 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 512 KB Output is correct
2 Correct 208 ms 540 KB Output is correct
3 Correct 207 ms 560 KB Output is correct