Submission #503351

#TimeUsernameProblemLanguageResultExecution timeMemory
503351CraniXortCalvinball championship (CEOI15_teams)C++17
100 / 100
111 ms588 KiB
#include <bits/stdc++.h> #define fin std::cin #define fout std::cout // std::ifstream fin("calvinball.in"); // std::ofstream fout("calvinball.out"); const long long mod = 1000007; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int n; fin >> n; std::vector <int> v(n), max(n); for(int i = 0; i < n; i ++) fin >> v[i]; max[0] = 0; for(int i = 1; i < n; i ++) max[i] = std::max(max[i-1], v[i-1]); long long dp[2][n+1], current = 0, next = 1; for(int i = 0; i < n; i ++) dp[current][i] = 1; long long ans = 0; for(int i = n-1; i >= 0; i--, current ^= 1, next ^= 1) { ans = ans + (v[i] - 1) * dp[current][max[i]]; ans %= mod; for(int j = 0; j < i; j ++) dp[next][j] = (j * dp[current][j] + dp[current][j+1]) % mod; } fout << (1 + ans) % mod << '\n'; return 0; }
#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...