Submission #530741

# Submission time Handle Problem Language Result Execution time Memory
530741 2022-02-26T15:55:24 Z Yazan_Alattar Calvinball championship (CEOI15_teams) C++14
100 / 100
595 ms 716 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);
		for(int i = 0; i <= n; ++i) dp[i] = 0;
	}
	
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 460 KB Output is correct
2 Correct 6 ms 408 KB Output is correct
3 Correct 8 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 579 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 540 KB Output is correct
2 Correct 149 ms 528 KB Output is correct
3 Correct 147 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 590 ms 716 KB Output is correct
2 Correct 595 ms 612 KB Output is correct
3 Correct 584 ms 624 KB Output is correct