답안 #849152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849152 2023-09-14T07:27:34 Z tch1cherin Boat (APIO16_boat) C++17
58 / 100
2000 ms 12644 KB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

int inverse(int x) {
  int base = x, power = MOD - 2;
  int result = 1;
  while (power > 0) {
    if (power & 1) {
      result = 1LL * result * base % MOD;
    }
    base = 1LL * base * base % MOD;
    power /= 2;
  }
  return result;
}

void norm(int& X) {
  X -= X >= MOD ? MOD : 0;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  vector<int> points;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    points.push_back(A[i]);
    points.push_back(B[i]);
  }
  sort(points.begin(), points.end());
  points.resize(unique(points.begin(), points.end()) - points.begin());
  vector<int> new_points;
  for (int i = 0; i < (int)points.size(); i++) {
    new_points.push_back(points[i]);
    if (i + 1 < (int)points.size() && points[i + 1] - points[i] > 1) {
      new_points.push_back(points[i] + 1);
    } 
  }
  points = new_points;
  int M = (int)points.size();
  vector<int> weight(M);
  vector<vector<int>> choose_weight(M, vector<int>(N + 1));
  for (int i = 0; i < M; i++) {
    weight[i] = (i == M - 1 ? 1 : points[i + 1] - points[i]);
    choose_weight[i][0] = 1;
    for (int j = 0; j < weight[i] && j < N; j++) {
      int coefficient = 1LL * (weight[i] - j) * inverse(j + 1) % MOD;  
      choose_weight[i][j + 1] = 1LL * choose_weight[i][j] * coefficient % MOD;
    }
  }
  vector<vector<int>> ways(M, vector<int>(N + 1));
  vector<int> pref(M + 1);
  for (int i = 0; i < M; i++) {
    ways[i][0] = 1;
  }
  for (int i = 0; i < N; i++) {
    vector<vector<int>> new_ways(M, vector<int>(N + 1));
    for (int j = 0; j < M; j++) {
      if (A[i] <= points[j] && points[j] <= B[i]) {
        new_ways[j][1] += pref[j];
      }
      for (int k = 0; k < N; k++) {
        norm(new_ways[j][k] += ways[j][k]);
        if (A[i] <= points[j] && points[j] <= B[i]) {
          norm(new_ways[j][k + 1] += ways[j][k]);
        }
      }
    }
    for (int j = 0; j < M; j++) {
      pref[j + 1] = pref[j];
      for (int k = 1; k <= N && k <= weight[j]; k++) {
        pref[j + 1] = (pref[j + 1] + 1LL * new_ways[j][k] * choose_weight[j][k]) % MOD;
      }
    }
    ways = new_ways;
  }
  cout << pref[M] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1368 ms 6676 KB Output is correct
2 Correct 1373 ms 6588 KB Output is correct
3 Correct 1353 ms 6620 KB Output is correct
4 Correct 1358 ms 6708 KB Output is correct
5 Correct 1369 ms 6532 KB Output is correct
6 Correct 1354 ms 6680 KB Output is correct
7 Correct 1374 ms 6828 KB Output is correct
8 Correct 1406 ms 6720 KB Output is correct
9 Correct 1371 ms 6632 KB Output is correct
10 Correct 1360 ms 6560 KB Output is correct
11 Correct 1364 ms 6680 KB Output is correct
12 Correct 1372 ms 6492 KB Output is correct
13 Correct 1372 ms 6552 KB Output is correct
14 Correct 1382 ms 6940 KB Output is correct
15 Correct 1397 ms 6980 KB Output is correct
16 Correct 226 ms 1508 KB Output is correct
17 Correct 250 ms 1896 KB Output is correct
18 Correct 238 ms 1552 KB Output is correct
19 Correct 253 ms 2008 KB Output is correct
20 Correct 239 ms 1564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1368 ms 6676 KB Output is correct
2 Correct 1373 ms 6588 KB Output is correct
3 Correct 1353 ms 6620 KB Output is correct
4 Correct 1358 ms 6708 KB Output is correct
5 Correct 1369 ms 6532 KB Output is correct
6 Correct 1354 ms 6680 KB Output is correct
7 Correct 1374 ms 6828 KB Output is correct
8 Correct 1406 ms 6720 KB Output is correct
9 Correct 1371 ms 6632 KB Output is correct
10 Correct 1360 ms 6560 KB Output is correct
11 Correct 1364 ms 6680 KB Output is correct
12 Correct 1372 ms 6492 KB Output is correct
13 Correct 1372 ms 6552 KB Output is correct
14 Correct 1382 ms 6940 KB Output is correct
15 Correct 1397 ms 6980 KB Output is correct
16 Correct 226 ms 1508 KB Output is correct
17 Correct 250 ms 1896 KB Output is correct
18 Correct 238 ms 1552 KB Output is correct
19 Correct 253 ms 2008 KB Output is correct
20 Correct 239 ms 1564 KB Output is correct
21 Correct 1091 ms 10764 KB Output is correct
22 Correct 1075 ms 10832 KB Output is correct
23 Correct 1088 ms 10864 KB Output is correct
24 Correct 1109 ms 10848 KB Output is correct
25 Correct 1061 ms 10648 KB Output is correct
26 Correct 1103 ms 10168 KB Output is correct
27 Correct 1089 ms 10268 KB Output is correct
28 Correct 1088 ms 10284 KB Output is correct
29 Correct 1137 ms 10212 KB Output is correct
30 Correct 1838 ms 12072 KB Output is correct
31 Correct 1846 ms 11592 KB Output is correct
32 Correct 1801 ms 11960 KB Output is correct
33 Correct 1854 ms 11900 KB Output is correct
34 Correct 1784 ms 11888 KB Output is correct
35 Correct 1274 ms 6740 KB Output is correct
36 Correct 1299 ms 6576 KB Output is correct
37 Correct 1337 ms 6744 KB Output is correct
38 Correct 1298 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 952 KB Output is correct
2 Correct 24 ms 952 KB Output is correct
3 Correct 27 ms 952 KB Output is correct
4 Correct 25 ms 952 KB Output is correct
5 Correct 25 ms 952 KB Output is correct
6 Correct 25 ms 952 KB Output is correct
7 Correct 26 ms 1176 KB Output is correct
8 Correct 26 ms 952 KB Output is correct
9 Correct 28 ms 1116 KB Output is correct
10 Correct 25 ms 952 KB Output is correct
11 Correct 25 ms 952 KB Output is correct
12 Correct 24 ms 956 KB Output is correct
13 Correct 25 ms 952 KB Output is correct
14 Correct 25 ms 952 KB Output is correct
15 Correct 24 ms 956 KB Output is correct
16 Correct 10 ms 600 KB Output is correct
17 Correct 12 ms 600 KB Output is correct
18 Correct 11 ms 600 KB Output is correct
19 Correct 10 ms 600 KB Output is correct
20 Correct 13 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1368 ms 6676 KB Output is correct
2 Correct 1373 ms 6588 KB Output is correct
3 Correct 1353 ms 6620 KB Output is correct
4 Correct 1358 ms 6708 KB Output is correct
5 Correct 1369 ms 6532 KB Output is correct
6 Correct 1354 ms 6680 KB Output is correct
7 Correct 1374 ms 6828 KB Output is correct
8 Correct 1406 ms 6720 KB Output is correct
9 Correct 1371 ms 6632 KB Output is correct
10 Correct 1360 ms 6560 KB Output is correct
11 Correct 1364 ms 6680 KB Output is correct
12 Correct 1372 ms 6492 KB Output is correct
13 Correct 1372 ms 6552 KB Output is correct
14 Correct 1382 ms 6940 KB Output is correct
15 Correct 1397 ms 6980 KB Output is correct
16 Correct 226 ms 1508 KB Output is correct
17 Correct 250 ms 1896 KB Output is correct
18 Correct 238 ms 1552 KB Output is correct
19 Correct 253 ms 2008 KB Output is correct
20 Correct 239 ms 1564 KB Output is correct
21 Correct 1091 ms 10764 KB Output is correct
22 Correct 1075 ms 10832 KB Output is correct
23 Correct 1088 ms 10864 KB Output is correct
24 Correct 1109 ms 10848 KB Output is correct
25 Correct 1061 ms 10648 KB Output is correct
26 Correct 1103 ms 10168 KB Output is correct
27 Correct 1089 ms 10268 KB Output is correct
28 Correct 1088 ms 10284 KB Output is correct
29 Correct 1137 ms 10212 KB Output is correct
30 Correct 1838 ms 12072 KB Output is correct
31 Correct 1846 ms 11592 KB Output is correct
32 Correct 1801 ms 11960 KB Output is correct
33 Correct 1854 ms 11900 KB Output is correct
34 Correct 1784 ms 11888 KB Output is correct
35 Correct 1274 ms 6740 KB Output is correct
36 Correct 1299 ms 6576 KB Output is correct
37 Correct 1337 ms 6744 KB Output is correct
38 Correct 1298 ms 6656 KB Output is correct
39 Correct 25 ms 952 KB Output is correct
40 Correct 24 ms 952 KB Output is correct
41 Correct 27 ms 952 KB Output is correct
42 Correct 25 ms 952 KB Output is correct
43 Correct 25 ms 952 KB Output is correct
44 Correct 25 ms 952 KB Output is correct
45 Correct 26 ms 1176 KB Output is correct
46 Correct 26 ms 952 KB Output is correct
47 Correct 28 ms 1116 KB Output is correct
48 Correct 25 ms 952 KB Output is correct
49 Correct 25 ms 952 KB Output is correct
50 Correct 24 ms 956 KB Output is correct
51 Correct 25 ms 952 KB Output is correct
52 Correct 25 ms 952 KB Output is correct
53 Correct 24 ms 956 KB Output is correct
54 Correct 10 ms 600 KB Output is correct
55 Correct 12 ms 600 KB Output is correct
56 Correct 11 ms 600 KB Output is correct
57 Correct 10 ms 600 KB Output is correct
58 Correct 13 ms 456 KB Output is correct
59 Execution timed out 2013 ms 12644 KB Time limit exceeded
60 Halted 0 ms 0 KB -