답안 #546301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546301 2022-04-07T05:55:47 Z Soumya1 Calvinball championship (CEOI15_teams) C++17
100 / 100
251 ms 468 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mod = 1e6 + 7;
void testCase() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<int> dp(n + 1, 1);
  vector<int> pre(n + 1);
  for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], a[i]);
  int ans = 0;
  for (int i = n - 1; i >= 1; i--) {
    vector<int> new_dp(n + 1);
    for (int j = 1; j <= n; j++) {
      new_dp[j] = (1LL * dp[j] * j + (j + 1 <= n ? dp[j + 1] : 0)) % mod;
    }
    ans += new_dp[pre[i]];
    if (ans >= mod) ans -= mod;
    for (int j = a[i + 1]; j <= pre[i] + 1; j++) {
      ans -= dp[max(j, pre[i])];
      if (ans < 0) ans += mod;
    }
    dp = new_dp;
  }
  cout << (ans + 1) % mod << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 5 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 380 KB Output is correct
2 Correct 68 ms 380 KB Output is correct
3 Correct 58 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 251 ms 468 KB Output is correct
2 Correct 231 ms 468 KB Output is correct
3 Correct 228 ms 468 KB Output is correct