답안 #569950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
569950 2022-05-28T10:35:38 Z 600Mihnea Calvinball championship (CEOI15_teams) C++17
100 / 100
815 ms 424 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int M =  1000007;

int add(int a, int b) {
  a += b;
  if (a >= M) return a - M;
  if (a < 0) return a + M;
  return a;
}

int mul(int a, int b) {
  return a * (ll) b % M;
}

void addup(int &a, int b) {
  a = add(a, b);
}

void mulup(int &a, int b) {
  a = mul(a, b);
}

const int N = 10000 + 7;
int n, a[N], mx[N], ways[N];

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);


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

  int sol = 1;
  for (int i = n; i >= 1; i--) {
    addup(sol, mul(a[i] - 1, ways[mx[i - 1]]));
    for (int j = 1; j <= n; j++) {
      ways[j] = add(mul(j, ways[j]), ways[j + 1]);
    }
  }
  cout << sol << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 348 KB Output is correct
2 Correct 10 ms 340 KB Output is correct
3 Correct 10 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 791 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 372 KB Output is correct
2 Correct 204 ms 376 KB Output is correct
3 Correct 203 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 815 ms 424 KB Output is correct
2 Correct 800 ms 420 KB Output is correct
3 Correct 797 ms 416 KB Output is correct