답안 #295750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295750 2020-09-09T21:33:27 Z eggag32 Calvinball championship (CEOI15_teams) C++17
70 / 100
694 ms 708 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e6 + 7;
const int mxN = 1e4 + 5;
 
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
 
int dp[2][mxN][2];
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	memset(dp, 0, sizeof(dp));
	dp[0][1][1] = 1;
	dp[0][1][0] = 0;
	repn(i, 1, n){
		int cur = i & 1, prev = 1 - cur;
		repn(j, 1, i + 1){
			//turn a 1 into a 0
			(dp[cur][j][0] += (dp[prev][j][1] * min(j, a[i] - 1)) % MOD) %= MOD;
			if((j + 1) < a[i]) (dp[cur][j + 1][0] += dp[prev][j][1] % MOD) %= MOD;
			//update the 0 guy
			(dp[cur][j][0] += (dp[prev][j][0] * j) % MOD) %= MOD;
			(dp[cur][j + 1][0] += dp[prev][j][0]) %= MOD;
			//update the 1 guy
			(dp[cur][max(j, a[i])][1] += dp[prev][j][1]) %= MOD;
		}
		memset(dp[prev], 0, sizeof(dp[prev]));
	}
	int ans = 0;
	repn(i, 1, n + 1) ans = (ans + dp[(n - 1) & 1][i][0]) % MOD;
	cout << ans + 1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 544 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 8 ms 512 KB Output is correct
3 Correct 10 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 694 ms 580 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 145 ms 560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 544 ms 708 KB Output isn't correct
2 Halted 0 ms 0 KB -