답안 #530742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530742 2022-02-26T15:56:25 Z Yazan_Alattar Calvinball championship (CEOI15_teams) C++14
100 / 100
533 ms 588 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 10007;
const ll inf = 2e9;
const ll mod = 1e6 + 7;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
 
ll n, a[M], pref[M], ans = 1;
vector <ll> dp(M), old(M);
 
ll getDp(int j){ return (dp[j] - dp[j - 1] + mod) % mod; }
ll getOld(int j){ return (old[j] - old[j - 1] + mod) % mod; }
 
int main(){
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i], pref[i] = max(pref[i - 1], a[i]);
 
	for(int i = n; i; --i){
		for(ll j = 1; j <= i; ++j){
			if(i == n) dp[j] = j;
			else{
				dp[j] = dp[j - 1];
				dp[j] = (dp[j] + getOld(j + 1)) % mod;
				dp[j] = (dp[j] + getOld(j) * j) % mod;
			}
		}
		ll add = getDp(pref[i - 1]) * min(pref[i - 1], a[i] - 1);
		if(a[i] > pref[i - 1]) add = (add + dp[a[i] - 1] - dp[pref[i - 1]] + mod) % mod;
		ans = (ans + add) % mod;
		
		swap(old, dp);
	}
	
	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 460 KB Output is correct
2 Correct 6 ms 460 KB Output is correct
3 Correct 7 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 527 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 584 KB Output is correct
2 Correct 130 ms 508 KB Output is correct
3 Correct 137 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 533 ms 588 KB Output is correct
2 Correct 525 ms 588 KB Output is correct
3 Correct 528 ms 588 KB Output is correct