Submission #418121

# Submission time Handle Problem Language Result Execution time Memory
418121 2021-06-05T06:18:05 Z 2qbingxuan Arranging Tickets (JOI17_arranging_tickets) C++14
0 / 100
1 ms 204 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));

    int ans = m;
    for (int i = 0; i <= m; i++) {
        vector<int> need(n);
        for (int j = 0; j < n; j++)
            need[j] = max(0, (pref[j] - i + 1) / 2);
        debug(i);
        pary(all(need));
        int cnt = 0;
        max_heap<pair<int,int>> pq;
        min_heap<int> cover;
        for (int j = 0, it = 0; j < n; j++) {
            while (it < m && seg[it].first <= j) {
                auto [l, r] = seg[it];
                pq.emplace(r, it);
                it++;
            }
            while (cover.size() && cover.top() <= i) cover.pop();
            while (cover.size() < need[j]) {
                if (pq.empty()) {
                    cnt = inf;
                    break;
                }
                auto [r, id] = pq.top(); pq.pop();
                cover.push(r);
                ++cnt;
            }
        }
        debug(i, cnt);
        ans = min(ans, i + cnt);
    }
    cout << ans + sum << '\n';
}

Compilation message

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:54:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for (auto [l, r]: seg)
      |               ^
arranging_tickets.cpp:72:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |                 auto [l, r] = seg[it];
      |                      ^
arranging_tickets.cpp:82:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |                 auto [r, id] = pq.top(); pq.pop();
      |                      ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -