Submission #527223

# Submission time Handle Problem Language Result Execution time Memory
527223 2022-02-17T03:54:43 Z maomao90 Calvinball championship (CEOI15_teams) C++17
70 / 100
714 ms 8340 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)

template<class T>
inline bool mxto(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T>
inline bool mnto(T &a, T b) {return a > b ? a = b, 1 : 0;}

typedef long long ll;
#define FI first
#define SE second
#define MP make_pair
typedef pair<int, int> ii;
#define pb push_back
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<ii> vii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 1005
#define MOD 1000007

int n;
int a[MAXN];

int memo[MAXN][MAXN][2];
int dp(int i, int j, bool same) {
	if (i >= n) {
		return 1;
	}
	if (memo[i][j][same] != -1) {
		return memo[i][j][same];
	}
	int res = 0;
	if (same) {
		REP (k, 1, min(j + 1, a[i])) {
			res += dp(i + 1, j, 0);
			if (res >= MOD) {
				res -= MOD;
			}
		}
		if (a[i] <= j + 1) {
			res += dp(i + 1, max(j, a[i]), 1);
			if (res >= MOD) {
				res -= MOD;
			}
		}
	} else {
		REP (k, 1, j + 1) {
			res += dp(i + 1, j, 0);
			if (res >= MOD) {
				res -= MOD;
			}
		}
		res += dp(i + 1, j + 1, 0);
		if (res >= MOD) {
			res -= MOD;
		}
	}
	return memo[i][j][same] = res;
}

int main() {
#ifndef DEBUG
	ios::sync_with_stdio(0), cin.tie(0);
#endif
	cin >> n;
	REP (i, 0, n) {
		cin >> a[i];
	}
	memset(memo, -1, sizeof memo);
	cout << dp(0, 0, 1) << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 3 ms 8140 KB Output is correct
4 Correct 3 ms 8140 KB Output is correct
5 Correct 3 ms 8140 KB Output is correct
6 Correct 3 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 3 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 4 ms 8220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8140 KB Output is correct
2 Correct 5 ms 8140 KB Output is correct
3 Correct 4 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 8256 KB Output is correct
2 Correct 95 ms 8140 KB Output is correct
3 Correct 94 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 696 ms 8296 KB Output is correct
2 Correct 680 ms 8296 KB Output is correct
3 Correct 690 ms 8296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 714 ms 8340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -