Submission #871922

# Submission time Handle Problem Language Result Execution time Memory
871922 2023-11-11T21:22:06 Z tvladm2009 Event Hopping 2 (JOI21_event2) C++17
8 / 100
41 ms 3036 KB
#include <bits/stdc++.h>
 
using i64 = long long;
 
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, k;
    std::cin >> n >> k;
    std::vector<int> l(n), r(n);
    for (int i = 0; i < n; i++) {
        std::cin >> l[i] >> r[i];
    }
    if (n <= 20) {
        std::vector<std::vector<int>> good; 
        for (int mask = 1; mask < (1 << n); mask++) {
            if (__builtin_popcount(mask) != k) {
                continue;
            }
            std::vector<std::pair<int, int>> v;
            for (int b = 0; b < n; b++) {
                if (mask & (1 << b)) {
                    v.push_back({l[b], r[b]});
                }
            }
            sort(v.begin(), v.end());
            bool ok = true;
            for (int i = 1; i < v.size(); i++) {
                if (v[i].first < v[i - 1].second) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                std::vector<int> rep;
                for (int b = 0; b < n; b++) {
                    if (mask & (1 << b)) {
                        rep.emplace_back(b);
                    }
                }
                good.emplace_back(rep);
            }
        }
        if (good.empty()) {
            std::cout << "-1\n";
            return 0;
        }
        std::sort(good.begin(), good.end());
        std::vector<int> sol = good[0];
        for (auto i : sol) {
            std::cout << i + 1 << "\n";
        }
        return 0;
    }

    std::vector<int> dp(n, 0), suff(n + 1, 0);
    for (int i = n - 1; i >= 0; i--) {
        int lft = i + 1, rgh = n - 1, pos = n;
        while (lft <= rgh) {
            int m = (lft + rgh) / 2;
            if (l[m] >= r[i]) {
                rgh = m - 1;
                pos = m;
            } else {
                lft = m + 1;
            }
        }
        dp[i] = suff[pos] + 1;
        suff[i] = std::max(suff[i + 1], dp[i]);
    }
    std::vector<int> sol;
    int last = 0;
    for (int i = 0; i < n; i++) {
        if (l[i] >= last && dp[i] >= k) {
            last = r[i];
            k--;
            sol.push_back(i + 1);
        }
        if (k == 0) {
            break;
        }
    }
    if (k > 0) {
        std::cout << "-1\n";
        return 0;
    }
    for (auto it : sol) {
        std::cout << it << "\n";
    }
    return 0;
}

Compilation message

event2.cpp: In function 'int main()':
event2.cpp:29:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             for (int i = 1; i < v.size(); i++) {
      |                             ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 22 ms 2920 KB Output is correct
5 Correct 22 ms 3024 KB Output is correct
6 Correct 21 ms 2776 KB Output is correct
7 Correct 21 ms 2776 KB Output is correct
8 Correct 22 ms 2848 KB Output is correct
9 Correct 23 ms 3036 KB Output is correct
10 Correct 21 ms 2780 KB Output is correct
11 Correct 21 ms 2772 KB Output is correct
12 Correct 21 ms 2528 KB Output is correct
13 Correct 21 ms 2592 KB Output is correct
14 Correct 20 ms 2416 KB Output is correct
15 Correct 24 ms 2516 KB Output is correct
16 Correct 19 ms 2140 KB Output is correct
17 Correct 23 ms 2140 KB Output is correct
18 Correct 18 ms 2140 KB Output is correct
19 Correct 20 ms 1884 KB Output is correct
20 Correct 19 ms 1884 KB Output is correct
21 Correct 20 ms 1880 KB Output is correct
22 Correct 22 ms 1884 KB Output is correct
23 Correct 21 ms 2080 KB Output is correct
24 Correct 21 ms 1884 KB Output is correct
25 Correct 21 ms 1884 KB Output is correct
26 Correct 22 ms 1884 KB Output is correct
27 Correct 27 ms 2020 KB Output is correct
28 Correct 19 ms 1884 KB Output is correct
29 Correct 17 ms 1884 KB Output is correct
30 Correct 18 ms 2040 KB Output is correct
31 Correct 24 ms 1888 KB Output is correct
32 Correct 22 ms 1884 KB Output is correct
33 Correct 24 ms 2036 KB Output is correct
34 Correct 19 ms 2416 KB Output is correct
35 Correct 18 ms 2396 KB Output is correct
36 Correct 18 ms 2020 KB Output is correct
37 Correct 19 ms 2524 KB Output is correct
38 Correct 19 ms 2780 KB Output is correct
39 Correct 19 ms 2528 KB Output is correct
40 Correct 19 ms 2404 KB Output is correct
41 Correct 19 ms 2528 KB Output is correct
42 Correct 16 ms 1884 KB Output is correct
43 Correct 19 ms 2528 KB Output is correct
44 Correct 20 ms 2524 KB Output is correct
45 Correct 20 ms 2596 KB Output is correct
46 Correct 19 ms 2528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 41 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 41 ms 348 KB Output is correct
17 Correct 27 ms 344 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 21 ms 344 KB Output is correct
20 Correct 40 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 7 ms 456 KB Output is correct
23 Correct 35 ms 604 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 41 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 41 ms 348 KB Output is correct
17 Correct 27 ms 344 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 21 ms 344 KB Output is correct
20 Correct 40 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 7 ms 456 KB Output is correct
23 Correct 35 ms 604 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 452 KB Output is correct
28 Incorrect 1 ms 852 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 22 ms 2920 KB Output is correct
5 Correct 22 ms 3024 KB Output is correct
6 Correct 21 ms 2776 KB Output is correct
7 Correct 21 ms 2776 KB Output is correct
8 Correct 22 ms 2848 KB Output is correct
9 Correct 23 ms 3036 KB Output is correct
10 Correct 21 ms 2780 KB Output is correct
11 Correct 21 ms 2772 KB Output is correct
12 Correct 21 ms 2528 KB Output is correct
13 Correct 21 ms 2592 KB Output is correct
14 Correct 20 ms 2416 KB Output is correct
15 Correct 24 ms 2516 KB Output is correct
16 Correct 19 ms 2140 KB Output is correct
17 Correct 23 ms 2140 KB Output is correct
18 Correct 18 ms 2140 KB Output is correct
19 Correct 20 ms 1884 KB Output is correct
20 Correct 19 ms 1884 KB Output is correct
21 Correct 20 ms 1880 KB Output is correct
22 Correct 22 ms 1884 KB Output is correct
23 Correct 21 ms 2080 KB Output is correct
24 Correct 21 ms 1884 KB Output is correct
25 Correct 21 ms 1884 KB Output is correct
26 Correct 22 ms 1884 KB Output is correct
27 Correct 27 ms 2020 KB Output is correct
28 Correct 19 ms 1884 KB Output is correct
29 Correct 17 ms 1884 KB Output is correct
30 Correct 18 ms 2040 KB Output is correct
31 Correct 24 ms 1888 KB Output is correct
32 Correct 22 ms 1884 KB Output is correct
33 Correct 24 ms 2036 KB Output is correct
34 Correct 19 ms 2416 KB Output is correct
35 Correct 18 ms 2396 KB Output is correct
36 Correct 18 ms 2020 KB Output is correct
37 Correct 19 ms 2524 KB Output is correct
38 Correct 19 ms 2780 KB Output is correct
39 Correct 19 ms 2528 KB Output is correct
40 Correct 19 ms 2404 KB Output is correct
41 Correct 19 ms 2528 KB Output is correct
42 Correct 16 ms 1884 KB Output is correct
43 Correct 19 ms 2528 KB Output is correct
44 Correct 20 ms 2524 KB Output is correct
45 Correct 20 ms 2596 KB Output is correct
46 Correct 19 ms 2528 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 3 ms 456 KB Output is correct
53 Correct 5 ms 344 KB Output is correct
54 Correct 3 ms 348 KB Output is correct
55 Correct 2 ms 464 KB Output is correct
56 Correct 3 ms 348 KB Output is correct
57 Correct 41 ms 348 KB Output is correct
58 Correct 3 ms 348 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 3 ms 348 KB Output is correct
61 Correct 2 ms 348 KB Output is correct
62 Correct 41 ms 348 KB Output is correct
63 Correct 27 ms 344 KB Output is correct
64 Correct 5 ms 348 KB Output is correct
65 Correct 21 ms 344 KB Output is correct
66 Correct 40 ms 348 KB Output is correct
67 Correct 3 ms 348 KB Output is correct
68 Correct 7 ms 456 KB Output is correct
69 Correct 35 ms 604 KB Output is correct
70 Correct 3 ms 344 KB Output is correct
71 Correct 2 ms 348 KB Output is correct
72 Correct 2 ms 348 KB Output is correct
73 Correct 3 ms 452 KB Output is correct
74 Incorrect 1 ms 852 KB Output isn't correct
75 Halted 0 ms 0 KB -