Submission #849153

# Submission time Handle Problem Language Result Execution time Memory
849153 2023-09-14T07:29:29 Z tch1cherin Boat (APIO16_boat) C++17
58 / 100
2000 ms 12576 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
#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";
}
# Verdict Execution time Memory Grader output
1 Correct 1115 ms 6856 KB Output is correct
2 Correct 1099 ms 6972 KB Output is correct
3 Correct 1137 ms 6684 KB Output is correct
4 Correct 1114 ms 6704 KB Output is correct
5 Correct 1121 ms 6992 KB Output is correct
6 Correct 1105 ms 6832 KB Output is correct
7 Correct 1127 ms 6616 KB Output is correct
8 Correct 1118 ms 6668 KB Output is correct
9 Correct 1114 ms 6888 KB Output is correct
10 Correct 1117 ms 6776 KB Output is correct
11 Correct 1105 ms 6500 KB Output is correct
12 Correct 1102 ms 6724 KB Output is correct
13 Correct 1124 ms 6824 KB Output is correct
14 Correct 1114 ms 6584 KB Output is correct
15 Correct 1125 ms 6864 KB Output is correct
16 Correct 193 ms 1676 KB Output is correct
17 Correct 202 ms 1592 KB Output is correct
18 Correct 202 ms 1712 KB Output is correct
19 Correct 198 ms 1596 KB Output is correct
20 Correct 192 ms 1568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1115 ms 6856 KB Output is correct
2 Correct 1099 ms 6972 KB Output is correct
3 Correct 1137 ms 6684 KB Output is correct
4 Correct 1114 ms 6704 KB Output is correct
5 Correct 1121 ms 6992 KB Output is correct
6 Correct 1105 ms 6832 KB Output is correct
7 Correct 1127 ms 6616 KB Output is correct
8 Correct 1118 ms 6668 KB Output is correct
9 Correct 1114 ms 6888 KB Output is correct
10 Correct 1117 ms 6776 KB Output is correct
11 Correct 1105 ms 6500 KB Output is correct
12 Correct 1102 ms 6724 KB Output is correct
13 Correct 1124 ms 6824 KB Output is correct
14 Correct 1114 ms 6584 KB Output is correct
15 Correct 1125 ms 6864 KB Output is correct
16 Correct 193 ms 1676 KB Output is correct
17 Correct 202 ms 1592 KB Output is correct
18 Correct 202 ms 1712 KB Output is correct
19 Correct 198 ms 1596 KB Output is correct
20 Correct 192 ms 1568 KB Output is correct
21 Correct 1139 ms 10804 KB Output is correct
22 Correct 1115 ms 10736 KB Output is correct
23 Correct 1105 ms 10600 KB Output is correct
24 Correct 1150 ms 10756 KB Output is correct
25 Correct 1102 ms 10492 KB Output is correct
26 Correct 1149 ms 10508 KB Output is correct
27 Correct 1169 ms 9984 KB Output is correct
28 Correct 1160 ms 10572 KB Output is correct
29 Correct 1202 ms 10320 KB Output is correct
30 Correct 1605 ms 12132 KB Output is correct
31 Correct 1603 ms 11856 KB Output is correct
32 Correct 1607 ms 11984 KB Output is correct
33 Correct 1631 ms 11828 KB Output is correct
34 Correct 1620 ms 11820 KB Output is correct
35 Correct 1104 ms 6644 KB Output is correct
36 Correct 1046 ms 6848 KB Output is correct
37 Correct 1083 ms 6708 KB Output is correct
38 Correct 1059 ms 6504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 952 KB Output is correct
2 Correct 21 ms 952 KB Output is correct
3 Correct 20 ms 952 KB Output is correct
4 Correct 20 ms 952 KB Output is correct
5 Correct 20 ms 952 KB Output is correct
6 Correct 21 ms 952 KB Output is correct
7 Correct 21 ms 952 KB Output is correct
8 Correct 22 ms 952 KB Output is correct
9 Correct 21 ms 952 KB Output is correct
10 Correct 21 ms 952 KB Output is correct
11 Correct 21 ms 980 KB Output is correct
12 Correct 22 ms 952 KB Output is correct
13 Correct 20 ms 956 KB Output is correct
14 Correct 21 ms 952 KB Output is correct
15 Correct 21 ms 952 KB Output is correct
16 Correct 8 ms 600 KB Output is correct
17 Correct 9 ms 600 KB Output is correct
18 Correct 9 ms 600 KB Output is correct
19 Correct 9 ms 600 KB Output is correct
20 Correct 9 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1115 ms 6856 KB Output is correct
2 Correct 1099 ms 6972 KB Output is correct
3 Correct 1137 ms 6684 KB Output is correct
4 Correct 1114 ms 6704 KB Output is correct
5 Correct 1121 ms 6992 KB Output is correct
6 Correct 1105 ms 6832 KB Output is correct
7 Correct 1127 ms 6616 KB Output is correct
8 Correct 1118 ms 6668 KB Output is correct
9 Correct 1114 ms 6888 KB Output is correct
10 Correct 1117 ms 6776 KB Output is correct
11 Correct 1105 ms 6500 KB Output is correct
12 Correct 1102 ms 6724 KB Output is correct
13 Correct 1124 ms 6824 KB Output is correct
14 Correct 1114 ms 6584 KB Output is correct
15 Correct 1125 ms 6864 KB Output is correct
16 Correct 193 ms 1676 KB Output is correct
17 Correct 202 ms 1592 KB Output is correct
18 Correct 202 ms 1712 KB Output is correct
19 Correct 198 ms 1596 KB Output is correct
20 Correct 192 ms 1568 KB Output is correct
21 Correct 1139 ms 10804 KB Output is correct
22 Correct 1115 ms 10736 KB Output is correct
23 Correct 1105 ms 10600 KB Output is correct
24 Correct 1150 ms 10756 KB Output is correct
25 Correct 1102 ms 10492 KB Output is correct
26 Correct 1149 ms 10508 KB Output is correct
27 Correct 1169 ms 9984 KB Output is correct
28 Correct 1160 ms 10572 KB Output is correct
29 Correct 1202 ms 10320 KB Output is correct
30 Correct 1605 ms 12132 KB Output is correct
31 Correct 1603 ms 11856 KB Output is correct
32 Correct 1607 ms 11984 KB Output is correct
33 Correct 1631 ms 11828 KB Output is correct
34 Correct 1620 ms 11820 KB Output is correct
35 Correct 1104 ms 6644 KB Output is correct
36 Correct 1046 ms 6848 KB Output is correct
37 Correct 1083 ms 6708 KB Output is correct
38 Correct 1059 ms 6504 KB Output is correct
39 Correct 21 ms 952 KB Output is correct
40 Correct 21 ms 952 KB Output is correct
41 Correct 20 ms 952 KB Output is correct
42 Correct 20 ms 952 KB Output is correct
43 Correct 20 ms 952 KB Output is correct
44 Correct 21 ms 952 KB Output is correct
45 Correct 21 ms 952 KB Output is correct
46 Correct 22 ms 952 KB Output is correct
47 Correct 21 ms 952 KB Output is correct
48 Correct 21 ms 952 KB Output is correct
49 Correct 21 ms 980 KB Output is correct
50 Correct 22 ms 952 KB Output is correct
51 Correct 20 ms 956 KB Output is correct
52 Correct 21 ms 952 KB Output is correct
53 Correct 21 ms 952 KB Output is correct
54 Correct 8 ms 600 KB Output is correct
55 Correct 9 ms 600 KB Output is correct
56 Correct 9 ms 600 KB Output is correct
57 Correct 9 ms 600 KB Output is correct
58 Correct 9 ms 600 KB Output is correct
59 Execution timed out 2041 ms 12576 KB Time limit exceeded
60 Halted 0 ms 0 KB -