제출 #245361

#제출 시각아이디문제언어결과실행 시간메모리
245361lycCalvinball championship (CEOI15_teams)C++14
100 / 100
396 ms736 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for (int i=(a);i>=(b);--i) const int mxN = 1e4+5; const int mod = 1e6+7; int N, A[mxN]; int dp[2][mxN][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; FOR(i,1,N){ cin >> A[i]; } FOR(j,0,N) FOR(x,0,1) dp[(N+1)&1][j][x] = 1; RFOR(i,N,1){ int c = i&1, p = !c; FOR(j,0,i-1){ dp[c][j][0] = 1LL * dp[p][j][0] * j % mod; dp[c][j][0] += dp[p][j+1][0]; dp[c][j][0] %= mod; if (j < A[i]) { dp[c][j][1] = 1LL * dp[p][j][0] * j % mod; dp[c][j][1] += dp[p][j+1][(j+1 == A[i])]; dp[c][j][1] %= mod; } else { dp[c][j][1] = 1LL * dp[p][j][0] * (A[i]-1) % mod; dp[c][j][1] += dp[p][j][1]; dp[c][j][1] %= mod; } //TRACE(i _ j _ "|" _ dp[c][j][0] _ dp[c][j][1]); } } cout << dp[1][0][1] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...