답안 #281255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281255 2020-08-23T04:10:48 Z AQT Calvinball championship (CEOI15_teams) C++14
100 / 100
296 ms 632 KB
#include <bits/stdc++.h>

using namespace std;

int N;
int arr[10005];
long long dp[2][10005];
const int MOD = 1000007;

int solve(int n, int m, bool border){
	if(n == N+1){
		return 1;
	}
	if(!border && n%2 == 0 && dp[n/2][m]){
		return dp[n/2][m];
	}
	int lim = m+1;
	if(border){
		lim = arr[n];
	}
	long long ans = 1LL * (lim-1) * solve(n+1, m, 0);
	ans += solve(n+1, max(lim, m), border);
	ans %= MOD;
	if(!border && n%2 == 0){
		dp[n/2][m] = ans;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N;
	for(int i = 1; i<=N; i++){
		cin >> arr[i];
		dp[1][i] = 1;
	}
	long long ans = 0;
	for(int i = N; i; i--){
		long long m = *max_element(arr, arr+i);
		ans += min(1LL*arr[i]-1, m) * dp[1][m];
		for(int j = 1; j<N; j++){
			dp[0][j] = 1LL * j * dp[1][j] + dp[1][j+1];
			dp[0][j] %= MOD;
			dp[1][j] = dp[0][j];
		}
		ans %= MOD;
	}
	cout << ans+1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 283 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 384 KB Output is correct
2 Correct 78 ms 504 KB Output is correct
3 Correct 76 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 284 ms 632 KB Output is correct
2 Correct 288 ms 608 KB Output is correct
3 Correct 296 ms 628 KB Output is correct