Submission #389223

# Submission time Handle Problem Language Result Execution time Memory
389223 2021-04-14T00:45:41 Z rama_pang Event Hopping 2 (JOI21_event2) C++17
100 / 100
234 ms 25732 KB
#include <bits/stdc++.h>
using namespace std;

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

  int N, K;
  cin >> N >> K;

  vector<int> L(N), R(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i] >> R[i];
  }

  { // Coordinate Compression
    vector<int> coords;
    for (int i = 0; i < N; i++) {
      coords.emplace_back(L[i]);
      coords.emplace_back(R[i]);
    }
    sort(begin(coords), end(coords));
    coords.resize(unique(begin(coords), end(coords)) - begin(coords));
    for (int i = 0; i < N; i++) {
      L[i] = lower_bound(begin(coords), end(coords), L[i]) - begin(coords);
      R[i] = lower_bound(begin(coords), end(coords), R[i]) - begin(coords);
    }
  }

  const int LOG = 17;
  vector<vector<int>> dp(LOG, vector<int>(2 * N + 2, 2 * N + 1));
  for (int i = 0; i < N; i++) {
    dp[0][L[i]] = min(dp[0][L[i]], R[i]);
  }
  for (int i = 2 * N - 1; i >= 0; i--) {
    dp[0][i] = min(dp[0][i], dp[0][i + 1]);
  }
  for (int j = 1; j < LOG; j++) {
    for (int i = 0; i <= 2 * N; i++) {
      dp[j][i] = dp[j - 1][dp[j - 1][i]];
    }
  }
  const auto GetDP = [&](int L, int R) { // dp[L, R)
    int ans = 0;
    for (int j = LOG - 1; j >= 0; j--) {
      if (dp[j][L] <= R) {
        L = dp[j][L];
        ans |= 1 << j;
      }
    }
    return ans;
  };

  if (GetDP(0, 2 * N) < K) {
    cout << -1 << '\n';
    return 0;
  }

  vector<int> ans;
  set<int> active = {-1, 2 * N};
  for (int i = 0, curDP = GetDP(0, 2 * N - 1); i < N && ans.size() < K; i++) {
    if (*active.lower_bound(L[i]) < R[i]) continue;

    int loL = *prev(active.lower_bound(L[i])) + 1;
    int hiL = L[i];

    int loR = R[i];
    int hiR = *active.lower_bound(R[i]);

    int newDP = curDP - GetDP(loL, hiR) + GetDP(loL, hiL) + GetDP(loR, hiR) + 1;

    if (newDP >= K) {
      curDP = newDP;
      ans.emplace_back(i);
      for (int j = L[i]; j < R[i]; j++) {
        active.emplace(j);
      }
    }
  }

  assert(ans.size() == K);
  for (auto i : ans) {
    cout << i + 1 << '\n';
  }
  return 0;
}

Compilation message

event2.cpp: In function 'int main()':
event2.cpp:61:68: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |   for (int i = 0, curDP = GetDP(0, 2 * N - 1); i < N && ans.size() < K; i++) {
      |                                                         ~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from event2.cpp:1:
event2.cpp:81:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |   assert(ans.size() == K);
      |          ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 128 ms 21932 KB Output is correct
5 Correct 131 ms 21852 KB Output is correct
6 Correct 121 ms 21416 KB Output is correct
7 Correct 113 ms 20784 KB Output is correct
8 Correct 130 ms 21956 KB Output is correct
9 Correct 130 ms 21760 KB Output is correct
10 Correct 120 ms 21336 KB Output is correct
11 Correct 111 ms 20872 KB Output is correct
12 Correct 125 ms 22280 KB Output is correct
13 Correct 129 ms 22048 KB Output is correct
14 Correct 117 ms 21800 KB Output is correct
15 Correct 109 ms 21168 KB Output is correct
16 Correct 115 ms 24620 KB Output is correct
17 Correct 114 ms 24680 KB Output is correct
18 Correct 106 ms 23632 KB Output is correct
19 Correct 113 ms 25380 KB Output is correct
20 Correct 117 ms 25440 KB Output is correct
21 Correct 116 ms 25632 KB Output is correct
22 Correct 121 ms 25732 KB Output is correct
23 Correct 118 ms 25520 KB Output is correct
24 Correct 118 ms 25644 KB Output is correct
25 Correct 117 ms 25600 KB Output is correct
26 Correct 117 ms 25644 KB Output is correct
27 Correct 117 ms 25512 KB Output is correct
28 Correct 52 ms 17072 KB Output is correct
29 Correct 52 ms 17068 KB Output is correct
30 Correct 54 ms 17072 KB Output is correct
31 Correct 57 ms 17068 KB Output is correct
32 Correct 60 ms 17076 KB Output is correct
33 Correct 64 ms 17072 KB Output is correct
34 Correct 93 ms 19936 KB Output is correct
35 Correct 76 ms 18660 KB Output is correct
36 Correct 63 ms 17456 KB Output is correct
37 Correct 129 ms 23884 KB Output is correct
38 Correct 126 ms 23472 KB Output is correct
39 Correct 119 ms 23212 KB Output is correct
40 Correct 117 ms 22952 KB Output is correct
41 Correct 115 ms 22620 KB Output is correct
42 Correct 64 ms 17064 KB Output is correct
43 Correct 142 ms 23904 KB Output is correct
44 Correct 139 ms 23976 KB Output is correct
45 Correct 134 ms 24068 KB Output is correct
46 Correct 137 ms 24140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 3 ms 968 KB Output is correct
29 Correct 3 ms 844 KB Output is correct
30 Correct 3 ms 972 KB Output is correct
31 Correct 4 ms 972 KB Output is correct
32 Correct 4 ms 972 KB Output is correct
33 Correct 3 ms 716 KB Output is correct
34 Correct 3 ms 716 KB Output is correct
35 Correct 5 ms 972 KB Output is correct
36 Correct 5 ms 844 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 3 ms 716 KB Output is correct
39 Correct 5 ms 972 KB Output is correct
40 Correct 4 ms 844 KB Output is correct
41 Correct 4 ms 844 KB Output is correct
42 Correct 2 ms 716 KB Output is correct
43 Correct 4 ms 972 KB Output is correct
44 Correct 4 ms 972 KB Output is correct
45 Correct 4 ms 976 KB Output is correct
46 Correct 3 ms 716 KB Output is correct
47 Correct 4 ms 972 KB Output is correct
48 Correct 5 ms 972 KB Output is correct
49 Correct 4 ms 972 KB Output is correct
50 Correct 3 ms 716 KB Output is correct
51 Correct 4 ms 972 KB Output is correct
52 Correct 4 ms 972 KB Output is correct
53 Correct 4 ms 972 KB Output is correct
54 Correct 3 ms 716 KB Output is correct
55 Correct 4 ms 972 KB Output is correct
56 Correct 3 ms 972 KB Output is correct
57 Correct 3 ms 972 KB Output is correct
58 Correct 4 ms 972 KB Output is correct
59 Correct 3 ms 972 KB Output is correct
60 Correct 3 ms 844 KB Output is correct
61 Correct 3 ms 844 KB Output is correct
62 Correct 3 ms 844 KB Output is correct
63 Correct 4 ms 844 KB Output is correct
64 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 128 ms 21932 KB Output is correct
5 Correct 131 ms 21852 KB Output is correct
6 Correct 121 ms 21416 KB Output is correct
7 Correct 113 ms 20784 KB Output is correct
8 Correct 130 ms 21956 KB Output is correct
9 Correct 130 ms 21760 KB Output is correct
10 Correct 120 ms 21336 KB Output is correct
11 Correct 111 ms 20872 KB Output is correct
12 Correct 125 ms 22280 KB Output is correct
13 Correct 129 ms 22048 KB Output is correct
14 Correct 117 ms 21800 KB Output is correct
15 Correct 109 ms 21168 KB Output is correct
16 Correct 115 ms 24620 KB Output is correct
17 Correct 114 ms 24680 KB Output is correct
18 Correct 106 ms 23632 KB Output is correct
19 Correct 113 ms 25380 KB Output is correct
20 Correct 117 ms 25440 KB Output is correct
21 Correct 116 ms 25632 KB Output is correct
22 Correct 121 ms 25732 KB Output is correct
23 Correct 118 ms 25520 KB Output is correct
24 Correct 118 ms 25644 KB Output is correct
25 Correct 117 ms 25600 KB Output is correct
26 Correct 117 ms 25644 KB Output is correct
27 Correct 117 ms 25512 KB Output is correct
28 Correct 52 ms 17072 KB Output is correct
29 Correct 52 ms 17068 KB Output is correct
30 Correct 54 ms 17072 KB Output is correct
31 Correct 57 ms 17068 KB Output is correct
32 Correct 60 ms 17076 KB Output is correct
33 Correct 64 ms 17072 KB Output is correct
34 Correct 93 ms 19936 KB Output is correct
35 Correct 76 ms 18660 KB Output is correct
36 Correct 63 ms 17456 KB Output is correct
37 Correct 129 ms 23884 KB Output is correct
38 Correct 126 ms 23472 KB Output is correct
39 Correct 119 ms 23212 KB Output is correct
40 Correct 117 ms 22952 KB Output is correct
41 Correct 115 ms 22620 KB Output is correct
42 Correct 64 ms 17064 KB Output is correct
43 Correct 142 ms 23904 KB Output is correct
44 Correct 139 ms 23976 KB Output is correct
45 Correct 134 ms 24068 KB Output is correct
46 Correct 137 ms 24140 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 312 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 320 KB Output is correct
56 Correct 1 ms 316 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 0 ms 204 KB Output is correct
70 Correct 0 ms 204 KB Output is correct
71 Correct 1 ms 316 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 1 ms 204 KB Output is correct
74 Correct 3 ms 968 KB Output is correct
75 Correct 3 ms 844 KB Output is correct
76 Correct 3 ms 972 KB Output is correct
77 Correct 4 ms 972 KB Output is correct
78 Correct 4 ms 972 KB Output is correct
79 Correct 3 ms 716 KB Output is correct
80 Correct 3 ms 716 KB Output is correct
81 Correct 5 ms 972 KB Output is correct
82 Correct 5 ms 844 KB Output is correct
83 Correct 4 ms 844 KB Output is correct
84 Correct 3 ms 716 KB Output is correct
85 Correct 5 ms 972 KB Output is correct
86 Correct 4 ms 844 KB Output is correct
87 Correct 4 ms 844 KB Output is correct
88 Correct 2 ms 716 KB Output is correct
89 Correct 4 ms 972 KB Output is correct
90 Correct 4 ms 972 KB Output is correct
91 Correct 4 ms 976 KB Output is correct
92 Correct 3 ms 716 KB Output is correct
93 Correct 4 ms 972 KB Output is correct
94 Correct 5 ms 972 KB Output is correct
95 Correct 4 ms 972 KB Output is correct
96 Correct 3 ms 716 KB Output is correct
97 Correct 4 ms 972 KB Output is correct
98 Correct 4 ms 972 KB Output is correct
99 Correct 4 ms 972 KB Output is correct
100 Correct 3 ms 716 KB Output is correct
101 Correct 4 ms 972 KB Output is correct
102 Correct 3 ms 972 KB Output is correct
103 Correct 3 ms 972 KB Output is correct
104 Correct 4 ms 972 KB Output is correct
105 Correct 3 ms 972 KB Output is correct
106 Correct 3 ms 844 KB Output is correct
107 Correct 3 ms 844 KB Output is correct
108 Correct 3 ms 844 KB Output is correct
109 Correct 4 ms 844 KB Output is correct
110 Correct 2 ms 716 KB Output is correct
111 Correct 128 ms 21852 KB Output is correct
112 Correct 137 ms 22320 KB Output is correct
113 Correct 139 ms 22700 KB Output is correct
114 Correct 152 ms 24240 KB Output is correct
115 Correct 163 ms 25028 KB Output is correct
116 Correct 83 ms 17068 KB Output is correct
117 Correct 82 ms 17072 KB Output is correct
118 Correct 234 ms 21880 KB Output is correct
119 Correct 214 ms 21400 KB Output is correct
120 Correct 177 ms 21164 KB Output is correct
121 Correct 79 ms 17076 KB Output is correct
122 Correct 211 ms 22260 KB Output is correct
123 Correct 199 ms 21676 KB Output is correct
124 Correct 178 ms 21180 KB Output is correct
125 Correct 85 ms 17228 KB Output is correct
126 Correct 179 ms 24104 KB Output is correct
127 Correct 169 ms 23600 KB Output is correct
128 Correct 156 ms 23080 KB Output is correct
129 Correct 80 ms 17076 KB Output is correct
130 Correct 166 ms 25076 KB Output is correct
131 Correct 158 ms 24748 KB Output is correct
132 Correct 156 ms 24368 KB Output is correct
133 Correct 82 ms 17236 KB Output is correct
134 Correct 157 ms 25520 KB Output is correct
135 Correct 153 ms 25296 KB Output is correct
136 Correct 146 ms 24868 KB Output is correct
137 Correct 83 ms 17136 KB Output is correct
138 Correct 152 ms 25480 KB Output is correct
139 Correct 150 ms 25584 KB Output is correct
140 Correct 127 ms 25004 KB Output is correct
141 Correct 82 ms 17024 KB Output is correct
142 Correct 133 ms 21924 KB Output is correct
143 Correct 127 ms 21932 KB Output is correct
144 Correct 130 ms 21932 KB Output is correct
145 Correct 107 ms 21980 KB Output is correct
146 Correct 107 ms 21804 KB Output is correct
147 Correct 109 ms 21668 KB Output is correct
148 Correct 104 ms 21680 KB Output is correct
149 Correct 109 ms 21552 KB Output is correct
150 Correct 102 ms 21416 KB Output is correct
151 Correct 97 ms 20776 KB Output is correct
152 Correct 50 ms 17072 KB Output is correct
153 Correct 110 ms 22064 KB Output is correct
154 Correct 107 ms 21912 KB Output is correct
155 Correct 106 ms 21736 KB Output is correct
156 Correct 107 ms 21724 KB Output is correct
157 Correct 108 ms 21548 KB Output is correct
158 Correct 104 ms 21420 KB Output is correct
159 Correct 96 ms 20772 KB Output is correct
160 Correct 51 ms 17072 KB Output is correct
161 Correct 179 ms 21488 KB Output is correct
162 Correct 179 ms 21224 KB Output is correct
163 Correct 163 ms 21040 KB Output is correct
164 Correct 160 ms 20908 KB Output is correct
165 Correct 167 ms 20836 KB Output is correct
166 Correct 60 ms 17072 KB Output is correct
167 Correct 142 ms 23920 KB Output is correct
168 Correct 133 ms 23848 KB Output is correct
169 Correct 137 ms 24136 KB Output is correct
170 Correct 128 ms 24064 KB Output is correct
171 Correct 107 ms 20796 KB Output is correct
172 Correct 114 ms 21552 KB Output is correct
173 Correct 178 ms 21668 KB Output is correct
174 Correct 175 ms 21428 KB Output is correct
175 Correct 175 ms 21356 KB Output is correct
176 Correct 144 ms 20388 KB Output is correct