Submission #418147

# Submission time Handle Problem Language Result Execution time Memory
418147 2021-06-05T07:16:31 Z 2qbingxuan Arranging Tickets (JOI17_arranging_tickets) C++14
85 / 100
1039 ms 4556 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define get_pos(u,x) int(lower_bound(all(u),x)-begin(u))

using namespace std;
using ll = int_fast64_t;
using ld = long double;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
const int inf = 1e9;
const int mod = 1000000007;
const ll INF = 1e18;
const int maxn = 5002;

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> seg;
    ll sum = 0;
    for (int i = 0; i < m; i++) {
        int l, r, c;
        cin >> l >> r >> c;
        if (l > r) swap(l, r);
        --l, --r;
        if (c % 2 == 1)
            seg.pb(l, r);
        sum += c / 2;
    }

    vector<int> pref(n);
    for (auto [l, r]: seg)
        pref[l] += 1, pref[r] -= 1;
    for (int i = 1; i < n; i++) pref[i] += pref[i-1];

    sort(all(seg));

    auto calc = [&](int x) {
        vector<int> need(n);
        for (int i = 0; i < n; i++)
            need[i] = max(0, (pref[i] - x + 1) / 2);
        int cnt = 0;
        max_heap<pair<int,int>> pq;
        min_heap<int> cover;
        for (int i = 0, it = 0; i < n; i++) {
            while (it < seg.size() && seg[it].first <= i) {
                auto [l, r] = seg[it];
                pq.emplace(r, it);
                it++;
            }
            while (cover.size() && cover.top() <= i) cover.pop();
            while (cover.size() < need[i]) {
                assert (!pq.empty());
                auto [r, id] = pq.top(); pq.pop();
                cover.push(r);
                ++cnt;
            }
        }
        return x + cnt;
    };

    int p0 = 0;
    int p1 = 1;
    for (int s = 1 << 20; s > 1; s >>= 1) {
        if (calc(p0 + s - 2) > calc(p0 + s))
            p0 += s;
        if (calc(p1 + s - 2) > calc(p1 + s))
            p1 += s;
    }
    cout << sum + min(calc(p0), calc(p1)) << '\n';
}

Compilation message

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:53:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |     for (auto [l, r]: seg)
      |               ^
arranging_tickets.cpp: In lambda function:
arranging_tickets.cpp:68:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |                 auto [l, r] = seg[it];
      |                      ^
arranging_tickets.cpp:75:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |                 auto [r, id] = pq.top(); pq.pop();
      |                      ^
# 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 312 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 312 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 18 ms 424 KB Output is correct
29 Correct 18 ms 424 KB Output is correct
30 Correct 18 ms 424 KB Output is correct
31 Correct 18 ms 428 KB Output is correct
32 Correct 18 ms 424 KB Output is correct
33 Correct 18 ms 332 KB Output is correct
34 Correct 17 ms 424 KB Output is correct
35 Correct 17 ms 420 KB Output is correct
36 Correct 17 ms 324 KB Output is correct
37 Correct 13 ms 420 KB Output is correct
38 Correct 8 ms 332 KB Output is correct
39 Correct 9 ms 420 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 312 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 18 ms 424 KB Output is correct
29 Correct 18 ms 424 KB Output is correct
30 Correct 18 ms 424 KB Output is correct
31 Correct 18 ms 428 KB Output is correct
32 Correct 18 ms 424 KB Output is correct
33 Correct 18 ms 332 KB Output is correct
34 Correct 17 ms 424 KB Output is correct
35 Correct 17 ms 420 KB Output is correct
36 Correct 17 ms 324 KB Output is correct
37 Correct 13 ms 420 KB Output is correct
38 Correct 8 ms 332 KB Output is correct
39 Correct 9 ms 420 KB Output is correct
40 Correct 1002 ms 4484 KB Output is correct
41 Correct 1039 ms 4472 KB Output is correct
42 Correct 1000 ms 4508 KB Output is correct
43 Correct 996 ms 4496 KB Output is correct
44 Correct 1014 ms 4556 KB Output is correct
45 Correct 997 ms 4476 KB Output is correct
46 Correct 964 ms 4352 KB Output is correct
47 Correct 1010 ms 4328 KB Output is correct
48 Correct 928 ms 4336 KB Output is correct
49 Correct 602 ms 3700 KB Output is correct
50 Correct 356 ms 3804 KB Output is correct
51 Correct 556 ms 3712 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 312 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 18 ms 424 KB Output is correct
29 Correct 18 ms 424 KB Output is correct
30 Correct 18 ms 424 KB Output is correct
31 Correct 18 ms 428 KB Output is correct
32 Correct 18 ms 424 KB Output is correct
33 Correct 18 ms 332 KB Output is correct
34 Correct 17 ms 424 KB Output is correct
35 Correct 17 ms 420 KB Output is correct
36 Correct 17 ms 324 KB Output is correct
37 Correct 13 ms 420 KB Output is correct
38 Correct 8 ms 332 KB Output is correct
39 Correct 9 ms 420 KB Output is correct
40 Correct 1002 ms 4484 KB Output is correct
41 Correct 1039 ms 4472 KB Output is correct
42 Correct 1000 ms 4508 KB Output is correct
43 Correct 996 ms 4496 KB Output is correct
44 Correct 1014 ms 4556 KB Output is correct
45 Correct 997 ms 4476 KB Output is correct
46 Correct 964 ms 4352 KB Output is correct
47 Correct 1010 ms 4328 KB Output is correct
48 Correct 928 ms 4336 KB Output is correct
49 Correct 602 ms 3700 KB Output is correct
50 Correct 356 ms 3804 KB Output is correct
51 Correct 556 ms 3712 KB Output is correct
52 Incorrect 603 ms 3188 KB Output isn't correct
53 Halted 0 ms 0 KB -