Submission #37363

#TimeUsernameProblemLanguageResultExecution timeMemory
37363cheater2kCalvinball championship (CEOI15_teams)C++14
100 / 100
736 ms2668 KiB
#include <bits/stdc++.h> using namespace std; const int N = 10005; const int md = 1000007; int n, a[N], b[N], dp[2][N], ans; vector< pair<int,int> > vec[N]; void add(int &x, int y) { x += y; while(x >= md) x -= md; if (x < 0) x += md; } int main() { scanf("%d", &n); int mx = 0; for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); int cur = min(a[i] - 1, mx); b[i] = mx; mx = max(mx, a[i]); a[i] = cur; vec[b[i]].push_back(make_pair(a[i], n - i)); } // + a[i] * dp[n - i][b[i]] dp[n & 1][0] = 1; for (int i = 1; i <= n; ++i) dp[n & 1][i] = 1LL * dp[n & 1][i - 1] * n % md; for (int ngroup = n - 1; ngroup >= 1; --ngroup) { int t = ngroup & 1; int cur = 1; dp[t][0] = 1; for (int i = 1; i <= n; ++i) { cur = ((1LL * cur * ngroup) + dp[t ^ 1][i - 1]) % md; dp[t][i] = cur; //printf("%d %d %d\n", ngroup, i, dp[t][i]); } for (auto it : vec[ngroup]) { add(ans, 1LL * it.first * dp[t][it.second] % md); } } printf("%d\n", (ans + 1) % md); }

Compilation message (stderr)

teams.cpp: In function 'int main()':
teams.cpp:15:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
teams.cpp:18:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
#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...