Submission #35981

# Submission time Handle Problem Language Result Execution time Memory
35981 2017-12-04T04:19:43 Z funcsr Calvinball championship (CEOI15_teams) C++14
10 / 100
1000 ms 2212 KB
#include <iostream>
#include <fstream>
#include <bitset>
#include <cassert>
#include <vector>
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF 1145141919
#define MOD 1000007
#define pb push_back
using namespace std;
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }

int N;
int A[10000];
int dp[2][2][10000];

bool verify_input() {
  int lm = -1;
  rep(i, N) {
    if (A[i] > lm+1) return false;
    if (A[i] == lm+1) lm++;
  }
  return true;
}

signed main() {
  cin >> N;
  rep(i, N) cin >> A[i], A[i]--;
  if (!verify_input()) {
    cout << 0 << "\n";
    return 0;
  }
  dp[0][0][0] = 1;
  for (int i=1; i<N; i++) {
    rep(k, 2) {
      rep(s, i+1) {
        if (dp[0][k][s] == 0) continue;
        if (k == 0) {
          add(dp[1][1][s], (1LL*A[i]*dp[0][0][s])%MOD);
          add(dp[1][0][max(s, A[i])], dp[0][0][s]);
        }
        else {
          int stay = s+1, go = 1;
          add(dp[1][1][s], (1LL*stay*dp[0][1][s])%MOD);
          add(dp[1][1][s+1], (1LL*go*dp[0][1][s])%MOD);
        }
      }
    }
    swap(dp[0], dp[1]);
  }
  int s = 0;
  rep(i, N) add(s, dp[0][1][i]);
  cout << s+1 << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2212 KB Output is correct
2 Correct 0 ms 2212 KB Output is correct
3 Correct 0 ms 2212 KB Output is correct
4 Correct 0 ms 2212 KB Output is correct
5 Correct 0 ms 2212 KB Output is correct
6 Correct 0 ms 2212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2212 KB Output is correct
2 Incorrect 0 ms 2212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2212 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 2212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 2212 KB Execution timed out
# Verdict Execution time Memory Grader output
1 Incorrect 326 ms 2212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 2212 KB Execution timed out
2 Halted 0 ms 0 KB -