답안 #833041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833041 2023-08-21T20:38:43 Z erray Boat (APIO16_boat) C++17
100 / 100
707 ms 4432 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG 
  #include "/home/eagle/ioi22/d2/debug.h"
#else 
  #define debug(...) void(37)
#endif

constexpr int md = int(1e9) + 7;
int add(int x, int y) {
  if ((x += y) > md) {
    x -= md;
  }
  return x;
}
int mul(int x, int y) {
  return 1LL * x * y % md;
}
int power(int x, int p) {
  int res = 1;
  while (p > 0) {
    if (p & 1) {
      res = mul(res, x);
    }
    x = mul(x, x);
    p >>= 1;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
    ++B[i];
  }
  vector<int> inv(N + 1);
  for (int i = 1; i <= N; ++i) {
    inv[i] = power(i, md - 2);
  }
  debug(inv);
  vector<int> ranges(2 * N);
  for (int i = 0; i < N; ++i) {
    ranges[2 * i] = A[i];
    ranges[2 * i + 1] = B[i];
  }
  sort(ranges.begin(), ranges.end());
  ranges.erase(unique(ranges.begin(), ranges.end()), ranges.end());
  const int S = int(ranges.size());
  vector<vector<int>> binom(S - 1, vector<int>(N + 1));
  for (int i = 0; i < S - 1; ++i) {
    int diff = ranges[i + 1] - ranges[i];
    binom[i][0] = 1;
    for (int j = 1; j <= min(N, diff); ++j) {
      binom[i][j] = mul(mul(binom[i][j - 1],  (diff - j + 1)), inv[j]);
    }
  }
  vector<vector<int>> dp(S, vector<int>(N + 1));
  for (int i = 0; i < S; ++i) {
    dp[i][0] = 1;
  }
  for (int i = 0; i < N; ++i) {
    int nw = 1;
    for (int j = 0; j < S - 1; ++j) {
      int a = 0;
      bool in_range = (A[i] <= ranges[j] && ranges[j + 1] <= B[i]);
      for (int k = N - 1; k > 0; --k) {
        if (k != 0) {
          a = add(a, mul(dp[j][k], binom[j][k]));
        } 
        if (in_range) {
          dp[j][k + 1] = add(dp[j][k + 1], dp[j][k]);
        }
      }
      if (in_range) {
        dp[j][1] = add(dp[j][1], nw);
      }
      nw = add(nw, a);
    }
  }
  int ans = 0;
  for (int i = 0; i < S - 1; ++i) {
    for (int j = 1; j <= N; ++j) {
      ans = add(ans, mul(dp[i][j], binom[i][j]));
    }
  }
  cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 587 ms 4308 KB Output is correct
2 Correct 592 ms 4432 KB Output is correct
3 Correct 588 ms 4308 KB Output is correct
4 Correct 585 ms 4308 KB Output is correct
5 Correct 587 ms 4308 KB Output is correct
6 Correct 585 ms 4308 KB Output is correct
7 Correct 589 ms 4308 KB Output is correct
8 Correct 588 ms 4432 KB Output is correct
9 Correct 585 ms 4308 KB Output is correct
10 Correct 592 ms 4308 KB Output is correct
11 Correct 580 ms 4432 KB Output is correct
12 Correct 586 ms 4308 KB Output is correct
13 Correct 586 ms 4308 KB Output is correct
14 Correct 585 ms 4308 KB Output is correct
15 Correct 577 ms 4308 KB Output is correct
16 Correct 101 ms 1020 KB Output is correct
17 Correct 113 ms 1072 KB Output is correct
18 Correct 106 ms 980 KB Output is correct
19 Correct 110 ms 1068 KB Output is correct
20 Correct 118 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 587 ms 4308 KB Output is correct
2 Correct 592 ms 4432 KB Output is correct
3 Correct 588 ms 4308 KB Output is correct
4 Correct 585 ms 4308 KB Output is correct
5 Correct 587 ms 4308 KB Output is correct
6 Correct 585 ms 4308 KB Output is correct
7 Correct 589 ms 4308 KB Output is correct
8 Correct 588 ms 4432 KB Output is correct
9 Correct 585 ms 4308 KB Output is correct
10 Correct 592 ms 4308 KB Output is correct
11 Correct 580 ms 4432 KB Output is correct
12 Correct 586 ms 4308 KB Output is correct
13 Correct 586 ms 4308 KB Output is correct
14 Correct 585 ms 4308 KB Output is correct
15 Correct 577 ms 4308 KB Output is correct
16 Correct 101 ms 1020 KB Output is correct
17 Correct 113 ms 1072 KB Output is correct
18 Correct 106 ms 980 KB Output is correct
19 Correct 110 ms 1068 KB Output is correct
20 Correct 118 ms 980 KB Output is correct
21 Correct 586 ms 3952 KB Output is correct
22 Correct 612 ms 4008 KB Output is correct
23 Correct 576 ms 4048 KB Output is correct
24 Correct 580 ms 3924 KB Output is correct
25 Correct 582 ms 3924 KB Output is correct
26 Correct 596 ms 3916 KB Output is correct
27 Correct 616 ms 3888 KB Output is correct
28 Correct 599 ms 3824 KB Output is correct
29 Correct 597 ms 3796 KB Output is correct
30 Correct 594 ms 4308 KB Output is correct
31 Correct 588 ms 4308 KB Output is correct
32 Correct 593 ms 4308 KB Output is correct
33 Correct 586 ms 4428 KB Output is correct
34 Correct 578 ms 4348 KB Output is correct
35 Correct 582 ms 4308 KB Output is correct
36 Correct 583 ms 4308 KB Output is correct
37 Correct 586 ms 4308 KB Output is correct
38 Correct 647 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 6 ms 468 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 6 ms 468 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 6 ms 492 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 6 ms 468 KB Output is correct
14 Correct 6 ms 468 KB Output is correct
15 Correct 6 ms 468 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 587 ms 4308 KB Output is correct
2 Correct 592 ms 4432 KB Output is correct
3 Correct 588 ms 4308 KB Output is correct
4 Correct 585 ms 4308 KB Output is correct
5 Correct 587 ms 4308 KB Output is correct
6 Correct 585 ms 4308 KB Output is correct
7 Correct 589 ms 4308 KB Output is correct
8 Correct 588 ms 4432 KB Output is correct
9 Correct 585 ms 4308 KB Output is correct
10 Correct 592 ms 4308 KB Output is correct
11 Correct 580 ms 4432 KB Output is correct
12 Correct 586 ms 4308 KB Output is correct
13 Correct 586 ms 4308 KB Output is correct
14 Correct 585 ms 4308 KB Output is correct
15 Correct 577 ms 4308 KB Output is correct
16 Correct 101 ms 1020 KB Output is correct
17 Correct 113 ms 1072 KB Output is correct
18 Correct 106 ms 980 KB Output is correct
19 Correct 110 ms 1068 KB Output is correct
20 Correct 118 ms 980 KB Output is correct
21 Correct 586 ms 3952 KB Output is correct
22 Correct 612 ms 4008 KB Output is correct
23 Correct 576 ms 4048 KB Output is correct
24 Correct 580 ms 3924 KB Output is correct
25 Correct 582 ms 3924 KB Output is correct
26 Correct 596 ms 3916 KB Output is correct
27 Correct 616 ms 3888 KB Output is correct
28 Correct 599 ms 3824 KB Output is correct
29 Correct 597 ms 3796 KB Output is correct
30 Correct 594 ms 4308 KB Output is correct
31 Correct 588 ms 4308 KB Output is correct
32 Correct 593 ms 4308 KB Output is correct
33 Correct 586 ms 4428 KB Output is correct
34 Correct 578 ms 4348 KB Output is correct
35 Correct 582 ms 4308 KB Output is correct
36 Correct 583 ms 4308 KB Output is correct
37 Correct 586 ms 4308 KB Output is correct
38 Correct 647 ms 4308 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 6 ms 468 KB Output is correct
41 Correct 6 ms 468 KB Output is correct
42 Correct 6 ms 468 KB Output is correct
43 Correct 6 ms 468 KB Output is correct
44 Correct 6 ms 468 KB Output is correct
45 Correct 6 ms 468 KB Output is correct
46 Correct 6 ms 468 KB Output is correct
47 Correct 6 ms 492 KB Output is correct
48 Correct 6 ms 468 KB Output is correct
49 Correct 7 ms 468 KB Output is correct
50 Correct 6 ms 468 KB Output is correct
51 Correct 6 ms 468 KB Output is correct
52 Correct 6 ms 468 KB Output is correct
53 Correct 6 ms 468 KB Output is correct
54 Correct 4 ms 340 KB Output is correct
55 Correct 4 ms 340 KB Output is correct
56 Correct 4 ms 340 KB Output is correct
57 Correct 4 ms 340 KB Output is correct
58 Correct 4 ms 340 KB Output is correct
59 Correct 662 ms 4308 KB Output is correct
60 Correct 659 ms 4428 KB Output is correct
61 Correct 667 ms 4428 KB Output is correct
62 Correct 657 ms 4320 KB Output is correct
63 Correct 664 ms 4316 KB Output is correct
64 Correct 707 ms 4308 KB Output is correct
65 Correct 704 ms 4432 KB Output is correct
66 Correct 685 ms 4312 KB Output is correct
67 Correct 705 ms 4428 KB Output is correct
68 Correct 699 ms 4308 KB Output is correct
69 Correct 659 ms 4312 KB Output is correct
70 Correct 650 ms 4312 KB Output is correct
71 Correct 651 ms 4312 KB Output is correct
72 Correct 660 ms 4316 KB Output is correct
73 Correct 666 ms 4312 KB Output is correct
74 Correct 122 ms 1036 KB Output is correct
75 Correct 121 ms 980 KB Output is correct
76 Correct 120 ms 1052 KB Output is correct
77 Correct 120 ms 980 KB Output is correct
78 Correct 120 ms 980 KB Output is correct