답안 #964587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964587 2024-04-17T07:06:54 Z Soumya1 Boat (APIO16_boat) C++17
100 / 100
1497 ms 12452 KB
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int dp[2005][501], ndp[2005][501];
int C[2005][501];
int power(int a, int b) {
  int r = 1;
  while (b > 0) {
    if (b & 1) r = (1LL * r * a) % mod;
    a = (1LL * a * a) % mod, b >>= 1;
  }
  return r;
}
void testCase() {
  int n;
  cin >> n;
  vector<int> l(n + 1), r(n + 1), all;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    all.push_back(l[i]);
    all.push_back(r[i]);
  }
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  vector<pair<int, int>> ranges;
  vector<int> range_id(all.size());
  for (int i = 0; i < all.size(); i++) {
    if (i > 0 && all[i - 1] + 1 <= all[i] - 1) ranges.push_back({all[i - 1] + 1, all[i] - 1});
    range_id[i] = ranges.size();
    ranges.push_back({all[i], all[i]});
  }
  auto get = [&](int x) {
    return lower_bound(all.begin(), all.end(), x) - all.begin();
  };
  int range_cnt = ranges.size();
  for (int i = 0; i < range_cnt; i++) {
    auto [L, R] = ranges[i];
    C[i][0] = 1;
    C[i][1] = (R - L + 1) % mod;
    for (int j = 2; j <= n; j++) {
      if (j > R - L + 1) C[i][j] = 0;
      else C[i][j] = (1LL * (1LL * C[i][j - 1] * (R - L + 1 - j + 1)) % mod * power(j, mod - 2)) % mod;
    }
  }
  for (int j = 0; j <= range_cnt; j++) dp[j][0] = 1;
  for (int i = 1; i <= n; i++) {
    int L = range_id[get(l[i])], R = range_id[get(r[i])];
    for (int j = L; j <= R; j++) {
      for (int k = 1; k <= n; k++) {
        ndp[j][k] = dp[j][k - 1];
        ndp[j + 1][0] += (1LL * ndp[j][k] * C[j][k]) % mod;
        if (ndp[j + 1][0] >= mod) ndp[j + 1][0] -= mod;
      }
      ndp[j + 1][0] += ndp[j][0];
      if (ndp[j + 1][0] >= mod) ndp[j + 1][0] -= mod;
    }
    for (int j = R + 1; j < range_cnt; j++) {
      ndp[j + 1][0] += ndp[j][0];
      if (ndp[j + 1][0] >= mod) ndp[j + 1][0] -= mod;
    }
    for (int j = 0; j <= range_cnt; j++) {
      for (int k = 0; k <= n; k++) {
        dp[j][k] += ndp[j][k];
        if (dp[j][k] >= mod) dp[j][k] -= mod;
        ndp[j][k] = 0;
      }
    }
  }
  int ans = dp[range_cnt][0] - 1;
  if (ans < 0) ans += mod;
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}

Compilation message

boat.cpp: In function 'void testCase()':
boat.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int i = 0; i < all.size(); i++) {
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 271 ms 9040 KB Output is correct
2 Correct 280 ms 9360 KB Output is correct
3 Correct 275 ms 9200 KB Output is correct
4 Correct 272 ms 9116 KB Output is correct
5 Correct 284 ms 9036 KB Output is correct
6 Correct 283 ms 10372 KB Output is correct
7 Correct 286 ms 10648 KB Output is correct
8 Correct 289 ms 10464 KB Output is correct
9 Correct 269 ms 10464 KB Output is correct
10 Correct 270 ms 10464 KB Output is correct
11 Correct 281 ms 10460 KB Output is correct
12 Correct 277 ms 10464 KB Output is correct
13 Correct 272 ms 10464 KB Output is correct
14 Correct 272 ms 10468 KB Output is correct
15 Correct 291 ms 10468 KB Output is correct
16 Correct 50 ms 6744 KB Output is correct
17 Correct 59 ms 6816 KB Output is correct
18 Correct 51 ms 6744 KB Output is correct
19 Correct 53 ms 6744 KB Output is correct
20 Correct 61 ms 6804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 271 ms 9040 KB Output is correct
2 Correct 280 ms 9360 KB Output is correct
3 Correct 275 ms 9200 KB Output is correct
4 Correct 272 ms 9116 KB Output is correct
5 Correct 284 ms 9036 KB Output is correct
6 Correct 283 ms 10372 KB Output is correct
7 Correct 286 ms 10648 KB Output is correct
8 Correct 289 ms 10464 KB Output is correct
9 Correct 269 ms 10464 KB Output is correct
10 Correct 270 ms 10464 KB Output is correct
11 Correct 281 ms 10460 KB Output is correct
12 Correct 277 ms 10464 KB Output is correct
13 Correct 272 ms 10464 KB Output is correct
14 Correct 272 ms 10468 KB Output is correct
15 Correct 291 ms 10468 KB Output is correct
16 Correct 50 ms 6744 KB Output is correct
17 Correct 59 ms 6816 KB Output is correct
18 Correct 51 ms 6744 KB Output is correct
19 Correct 53 ms 6744 KB Output is correct
20 Correct 61 ms 6804 KB Output is correct
21 Correct 957 ms 11616 KB Output is correct
22 Correct 919 ms 11644 KB Output is correct
23 Correct 901 ms 11608 KB Output is correct
24 Correct 925 ms 11640 KB Output is correct
25 Correct 921 ms 11600 KB Output is correct
26 Correct 1097 ms 11424 KB Output is correct
27 Correct 1099 ms 11444 KB Output is correct
28 Correct 1098 ms 11440 KB Output is correct
29 Correct 1113 ms 11356 KB Output is correct
30 Correct 490 ms 11856 KB Output is correct
31 Correct 483 ms 11976 KB Output is correct
32 Correct 511 ms 11968 KB Output is correct
33 Correct 482 ms 11860 KB Output is correct
34 Correct 494 ms 11960 KB Output is correct
35 Correct 270 ms 9052 KB Output is correct
36 Correct 272 ms 10576 KB Output is correct
37 Correct 268 ms 9208 KB Output is correct
38 Correct 301 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 10840 KB Output is correct
2 Correct 13 ms 10844 KB Output is correct
3 Correct 15 ms 10904 KB Output is correct
4 Correct 14 ms 10844 KB Output is correct
5 Correct 15 ms 9052 KB Output is correct
6 Correct 16 ms 10908 KB Output is correct
7 Correct 16 ms 10844 KB Output is correct
8 Correct 17 ms 10844 KB Output is correct
9 Correct 17 ms 10840 KB Output is correct
10 Correct 17 ms 10844 KB Output is correct
11 Correct 14 ms 9052 KB Output is correct
12 Correct 16 ms 9052 KB Output is correct
13 Correct 14 ms 10912 KB Output is correct
14 Correct 14 ms 10844 KB Output is correct
15 Correct 14 ms 10844 KB Output is correct
16 Correct 7 ms 6748 KB Output is correct
17 Correct 8 ms 6748 KB Output is correct
18 Correct 6 ms 6800 KB Output is correct
19 Correct 6 ms 6796 KB Output is correct
20 Correct 7 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 271 ms 9040 KB Output is correct
2 Correct 280 ms 9360 KB Output is correct
3 Correct 275 ms 9200 KB Output is correct
4 Correct 272 ms 9116 KB Output is correct
5 Correct 284 ms 9036 KB Output is correct
6 Correct 283 ms 10372 KB Output is correct
7 Correct 286 ms 10648 KB Output is correct
8 Correct 289 ms 10464 KB Output is correct
9 Correct 269 ms 10464 KB Output is correct
10 Correct 270 ms 10464 KB Output is correct
11 Correct 281 ms 10460 KB Output is correct
12 Correct 277 ms 10464 KB Output is correct
13 Correct 272 ms 10464 KB Output is correct
14 Correct 272 ms 10468 KB Output is correct
15 Correct 291 ms 10468 KB Output is correct
16 Correct 50 ms 6744 KB Output is correct
17 Correct 59 ms 6816 KB Output is correct
18 Correct 51 ms 6744 KB Output is correct
19 Correct 53 ms 6744 KB Output is correct
20 Correct 61 ms 6804 KB Output is correct
21 Correct 957 ms 11616 KB Output is correct
22 Correct 919 ms 11644 KB Output is correct
23 Correct 901 ms 11608 KB Output is correct
24 Correct 925 ms 11640 KB Output is correct
25 Correct 921 ms 11600 KB Output is correct
26 Correct 1097 ms 11424 KB Output is correct
27 Correct 1099 ms 11444 KB Output is correct
28 Correct 1098 ms 11440 KB Output is correct
29 Correct 1113 ms 11356 KB Output is correct
30 Correct 490 ms 11856 KB Output is correct
31 Correct 483 ms 11976 KB Output is correct
32 Correct 511 ms 11968 KB Output is correct
33 Correct 482 ms 11860 KB Output is correct
34 Correct 494 ms 11960 KB Output is correct
35 Correct 270 ms 9052 KB Output is correct
36 Correct 272 ms 10576 KB Output is correct
37 Correct 268 ms 9208 KB Output is correct
38 Correct 301 ms 9208 KB Output is correct
39 Correct 17 ms 10840 KB Output is correct
40 Correct 13 ms 10844 KB Output is correct
41 Correct 15 ms 10904 KB Output is correct
42 Correct 14 ms 10844 KB Output is correct
43 Correct 15 ms 9052 KB Output is correct
44 Correct 16 ms 10908 KB Output is correct
45 Correct 16 ms 10844 KB Output is correct
46 Correct 17 ms 10844 KB Output is correct
47 Correct 17 ms 10840 KB Output is correct
48 Correct 17 ms 10844 KB Output is correct
49 Correct 14 ms 9052 KB Output is correct
50 Correct 16 ms 9052 KB Output is correct
51 Correct 14 ms 10912 KB Output is correct
52 Correct 14 ms 10844 KB Output is correct
53 Correct 14 ms 10844 KB Output is correct
54 Correct 7 ms 6748 KB Output is correct
55 Correct 8 ms 6748 KB Output is correct
56 Correct 6 ms 6800 KB Output is correct
57 Correct 6 ms 6796 KB Output is correct
58 Correct 7 ms 7004 KB Output is correct
59 Correct 1200 ms 12272 KB Output is correct
60 Correct 1151 ms 12452 KB Output is correct
61 Correct 1172 ms 12276 KB Output is correct
62 Correct 1190 ms 12276 KB Output is correct
63 Correct 1201 ms 12272 KB Output is correct
64 Correct 1475 ms 12448 KB Output is correct
65 Correct 1497 ms 12272 KB Output is correct
66 Correct 1478 ms 12272 KB Output is correct
67 Correct 1483 ms 12268 KB Output is correct
68 Correct 1482 ms 12268 KB Output is correct
69 Correct 1144 ms 12372 KB Output is correct
70 Correct 1147 ms 12276 KB Output is correct
71 Correct 1157 ms 12268 KB Output is correct
72 Correct 1159 ms 12276 KB Output is correct
73 Correct 1155 ms 12268 KB Output is correct
74 Correct 118 ms 6748 KB Output is correct
75 Correct 127 ms 6744 KB Output is correct
76 Correct 118 ms 6900 KB Output is correct
77 Correct 121 ms 8856 KB Output is correct
78 Correct 125 ms 8860 KB Output is correct