Submission #1111169

#TimeUsernameProblemLanguageResultExecution timeMemory
1111169Ghulam_JunaidCalvinball championship (CEOI15_teams)C++17
70 / 100
16 ms16720 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e3 + 10; const ll mod = 1e6 + 7; ll n, ans, a[N], dp[N][N]; ll pwr(ll a, ll b){ if (b == 0) return 1; ll val = pwr(a, b/2); val *= val; val %= mod; if (b&1) val *= a; val %= mod; return val; } int main() { cin >> n; for (ll i=1; i<=n; i++){ cin >> a[i]; } for (ll i=n; i>0; i--){ for (ll j=1; j<=n; j++){ if (i==n){ dp[i][j] = dp[i][j-1] + 1; continue; } dp[i][j] = (j-1) * dp[i+1][j] + dp[i+1][j+1]; dp[i][j] %= mod; } } ll mx = 0; for (ll i=1; i<n; i++){ ans += (a[i] - 1) * dp[i+1][mx+1]; ans %= mod; mx = max(mx, a[i]); } ans += dp[n][a[n]]; ans %= mod; cout << ans << endl; }
#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...