Submission #530739

# Submission time Handle Problem Language Result Execution time Memory
530739 2022-02-26T15:41:30 Z Yazan_Alattar Calvinball championship (CEOI15_teams) C++14
70 / 100
121 ms 65540 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], dp[M][M], pref[M], ans = 1;

ll get(int i, int j){ return (dp[i][j] - dp[i][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 = 1; i <= n; ++i) dp[n][i] = i;
	for(int i = n - 1; i; --i){
		for(ll j = 1; j <= i; ++j){
			dp[i][j] = dp[i][j - 1];
			dp[i][j] = (dp[i][j] + get(i + 1, j + 1)) % mod;
			dp[i][j] = (dp[i][j] + get(i + 1, j) * j) % mod;
		}
	}
	
	for(int i = 1; i <= n; ++i){
		ll add = get(i, pref[i - 1]) * min(pref[i - 1], a[i] - 1);
		if(a[i] > pref[i - 1]) add = (add + dp[i][a[i] - 1] - dp[i][pref[i - 1]] + mod) % mod;
		ans = (ans + add) % mod;
	}
	
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 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 1 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3276 KB Output is correct
2 Correct 5 ms 3276 KB Output is correct
3 Correct 3 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8292 KB Output is correct
2 Correct 12 ms 8360 KB Output is correct
3 Correct 12 ms 8364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 116 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 114 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -