Submission #856608

# Submission time Handle Problem Language Result Execution time Memory
856608 2023-10-04T03:47:47 Z NeroZein Calvinball championship (CEOI15_teams) C++17
100 / 100
79 ms 668 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int md = 1000007;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> till(n); 
  for (int i = 0; i < n; ++i) {
    cin >> a[i]; 
  }
  for (int i = 1; i < n; ++i) {
    till[i] = max(till[i - 1], a[i - 1]); 
  }
  assert(a[0] == 1); 
  vector<long long> dp(n + 1), pd(n + 1); 
  for (int i = 1; i <= n; ++i) {
    pd[i] = 1; 
  }
  long long ans = 1; 
  for (int i = n - 1; i >= 0; --i) {
    ans += pd[till[i]] * (a[i] - 1); 
    ans %= md; 
    for (int j = 1; j < i; ++j) {
      dp[j] = pd[j] * j + pd[j + 1];
      dp[j] %= md; 
    }
    swap(dp, pd); 
  }
  cout << ans << '\n'; 
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 348 KB Output is correct
2 Correct 19 ms 348 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 604 KB Output is correct
2 Correct 75 ms 668 KB Output is correct
3 Correct 77 ms 668 KB Output is correct