답안 #476139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476139 2021-09-25T00:29:43 Z tmbao Calvinball championship (CEOI15_teams) C++14
100 / 100
118 ms 532 KB
#include <bits/stdc++.h>
using namespace std;

const int mod = 1000007;

int main() {
  // Input
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
  }

  // Solve
  vector<vector<long long>> dp;
  dp.resize(2);
  dp[0].resize(n + 1);
  dp[1].resize(n + 1);

  for (int i = 0, maxA = 0; i < n; ++i) {
    maxA = max(maxA, a[i] - 1);
    int currentI = i & 1;
    int previousI = currentI ^ 1;
    for (int j = 1; j <= i + 1; ++j) {
      dp[currentI][j] = (dp[previousI][j] * j + dp[previousI][j - 1]) % mod;
      if (j == maxA) {
        dp[currentI][j] = (dp[currentI][j] + a[i] - 1) % mod;
      }
    }
    maxA = max(maxA, a[i]);
  }

  long long ans = 1;
  for (int i = 1; i <= n; ++i) {
    ans = (ans + dp[n & 1 ^ 1][i]) % mod;
  }
  cout << ans;

  return 0;
}

Compilation message

teams.cpp: In function 'int main()':
teams.cpp:38:23: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   38 |     ans = (ans + dp[n & 1 ^ 1][i]) % mod;
      |                     ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 332 KB Output is correct
2 Correct 29 ms 424 KB Output is correct
3 Correct 31 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 460 KB Output is correct
2 Correct 109 ms 460 KB Output is correct
3 Correct 118 ms 532 KB Output is correct