Submission #113925

#TimeUsernameProblemLanguageResultExecution timeMemory
113925MercenaryCalvinball championship (CEOI15_teams)C++14
100 / 100
309 ms692 KiB
#include<bits/stdc++.h> using namespace std; #define taskname "A" #define pb push_back #define mp make_pair #ifndef LOCAL #define cerr if(0)cout #endif typedef long double ld; typedef long long ll; typedef pair<int,int> ii; const int maxn = 1e4 + 5; const int mod = 1e6 + 7; int a[maxn] , ma[maxn]; int dp[2][maxn]; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n; for(int i = 1 ; i <= n ; ++i)cin >> a[i]; for(int i = 1 ; i <= n ; ++i)ma[i] = max(ma[i - 1] , a[i]); int res = 1;bool bit = 0; for(int j = 0 ; j <= n ; ++j){ dp[0][j] = 1; } for(int i = n ; i >= 1 ; --i){ // res += (ll)(a[i] - 1) * dp[bit][ma[i - 1]] % mod; // cout << i << " " << dp[bit][ma[i]] << endl; if(res >= mod)res -= mod; bit ^= 1; for(int j = 1 ; j <= n ; ++j){ dp[bit][j] = dp[bit ^ 1][j + 1] + (ll)j * dp[bit ^ 1][j] % mod; if(dp[bit][j] >= mod)dp[bit][j] -= mod; if(j < a[i]){ res += dp[bit ^ 1][max(ma[i - 1],j)]; if(res >= mod)res -= mod; // cout << i << " " << max(ma[i - 1] , ) } } } cout << res; }

Compilation message (stderr)

teams.cpp: In function 'int main()':
teams.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...