Submission #230360

# Submission time Handle Problem Language Result Execution time Memory
230360 2020-05-09T17:10:38 Z Atalasion Calvinball championship (CEOI15_teams) C++14
100 / 100
235 ms 1016 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define int long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")
//9:00

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 10000 + 10;
const ll MOD = 1000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int dp[2][N][2], n, a[N];

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	bool f = 1;
	dp[0][0][0] = 1;
	int mx = 0;
	bool ff = 0;
	for (int i = 1; i <= n; i++){
		int nmx = max(mx, a[i]);
		memset(dp[f], 0, sizeof dp[f]);
		dp[f][nmx][0] = dp[f ^ 1][mx][0];
		//cout << dp[f][nmx][0] << '\n';
		for (int j = 1; j <= i; j++){
			dp[f][j][1] = (dp[f ^ 1][j - 1][1] + dp[f ^ 1][j][1] * 1ll * j % MOD) % MOD;
		}
		dp[f][mx][1] = (dp[f][mx][1] + dp[f ^ 1][mx][0] * 1ll * min(mx, a[i] - 1)  % MOD) % MOD; 
		mx = nmx; 
		f ^= 1;
	}
	ll res = 0;
	for (int i = 0; i <= n; i++){
		res += dp[f ^ 1][i][1];
	//	cout << i << ' ' << dp[f ^ 1][i][1] << '\n';
		res %= MOD;
	}
	res = (res + 1) % MOD;
	cout << res;









	return 0;
}

Compilation message

teams.cpp: In function 'int32_t main()':
teams.cpp:34:7: warning: unused variable 'ff' [-Wunused-variable]
  bool ff = 0;
       ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 640 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 640 KB Output is correct
2 Correct 11 ms 640 KB Output is correct
3 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 640 KB Output is correct
2 Correct 74 ms 764 KB Output is correct
3 Correct 77 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 233 ms 768 KB Output is correct
2 Correct 228 ms 768 KB Output is correct
3 Correct 235 ms 1016 KB Output is correct