답안 #476794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476794 2021-09-28T14:05:15 Z ntabc05101 Calvinball championship (CEOI15_teams) C++17
100 / 100
629 ms 588 KB
#include<bits/stdc++.h>
using namespace std;

#define taskname ""

const int mxN = 10000;
const int mod = 1e6 + 7;

long long dp[2][mxN + 1];
#define dp(x) dp[(x) & 1]
int a[mxN + 1], mx[mxN + 1];

int main() {
  if (fopen(taskname".inp", "r")) {
    freopen(taskname".inp", "r", stdin);
    freopen(taskname".out", "w", stdout);
  }
  else {
    if (fopen(taskname".in", "r")) {
      freopen(taskname".in", "r", stdin);
      freopen(taskname".out", "w", stdout);
    }
  }

  cin.tie(0)->sync_with_stdio(0);

  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx[i] = max(mx[i - 1], a[i]);
  }
  for (int i = 1; i <= n; i++) {
    dp(0)[i] = 1;
  }

  long long res = 1;
  for (int i = n - 1; i; i--) {
    for (int j = 1; j <= n; j++) {
      (dp(n - i)[j] = 1ll * j * dp(n - i - 1)[j]) %= mod;
      (dp(n - i)[j] += dp(n - i - 1)[j + 1]) %= mod;
    }
    
    for (int j = a[i] - 1; j; j--) {
      (res += dp(n - i)[max(mx[i - 1], j)]) %= mod;
    }
  }
  
  (res += a[n] - 1) %= mod;
  cout << res << "\n";

  return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen(taskname".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen(taskname".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:20:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |       freopen(taskname".in", "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:21:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |       freopen(taskname".out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 332 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
3 Correct 7 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 596 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 432 KB Output is correct
2 Correct 99 ms 460 KB Output is correct
3 Correct 156 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 528 KB Output is correct
2 Correct 377 ms 460 KB Output is correct
3 Correct 629 ms 588 KB Output is correct