답안 #617496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617496 2022-08-01T11:48:13 Z ollel Calvinball championship (CEOI15_teams) C++14
100 / 100
201 ms 676 KB
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i,a,b) for(int i = a; i < b; i++)

const ll MOD = 1000007;
const int MAXN = 10000;

int main() {
  int n; cin >> n;

  vi state(n);
  rep(i,0,n) cin >> state[i];

  int MAX = 1, LEFT = n;

  vector<pii> add(n);

  rep(i,0,n) {
    add[LEFT - 1] = {state[i] - 1, MAX};
    MAX = max(MAX, state[i]);
    LEFT--;
  }

  ll ans = 1;

  vector<vector<ll>> dp(2, vector<ll>(MAXN + 5, 1));
  rep(i,0,MAXN+1) dp[1][i] = i+1;
  ans = (ans + dp[0][ add[0].second ] * add[0].first) % MOD;
  ans = (ans + dp[1][ add[1].second ] * add[1].first) % MOD;
  rep(x,2,MAXN+1) {
    rep(y,0,MAXN+1) {
      dp[x&1][y] = (y * dp[(x - 1)&1][y] + dp[(x - 1)&1][y + 1]) % MOD;
    }
    if (x < n) ans = (ans + dp[x&1][ add[x].second ] * add[x].first) % MOD;
  }


  cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 528 KB Output is correct
2 Correct 161 ms 512 KB Output is correct
3 Correct 162 ms 508 KB Output is correct
4 Correct 159 ms 512 KB Output is correct
5 Correct 168 ms 508 KB Output is correct
6 Correct 180 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 512 KB Output is correct
2 Correct 158 ms 512 KB Output is correct
3 Correct 170 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 512 KB Output is correct
2 Correct 158 ms 528 KB Output is correct
3 Correct 161 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 160 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 468 KB Output is correct
2 Correct 163 ms 516 KB Output is correct
3 Correct 158 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 520 KB Output is correct
2 Correct 157 ms 524 KB Output is correct
3 Correct 169 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 528 KB Output is correct
2 Correct 160 ms 528 KB Output is correct
3 Correct 193 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 572 KB Output is correct
2 Correct 178 ms 596 KB Output is correct
3 Correct 201 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 596 KB Output is correct
2 Correct 164 ms 664 KB Output is correct
3 Correct 184 ms 676 KB Output is correct