結果

問題 No.580 旅館の予約計画
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-10-23 01:46:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 4,323 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 178,396 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 10:44:49
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
template<class T> struct PriorityQueue {
    vector<T> d;

    PriorityQueue() {}

    PriorityQueue(const vector<T> &d_) : d(d_) {
        make_heap();
    }

    template<class Iter> PriorityQueue(Iter first, Iter last) : d(first, last) {
        make_heap();
    }

    void push(const T &x) {
        int k = d.size();
        d.push_back(x);
        up(k);
    }

    void pop_min() {
        if (d.size() < 3u) {
            d.pop_back();
        }
        else {
            swap(d[1], d.back()); d.pop_back();
            int k = down(1);
            up(k);
        }
    }

    void pop_max() {
        if (d.size() < 2u) {
            d.pop_back();
        }
        else {
            swap(d[0], d.back()); d.pop_back();
            int k = down(0);
            up(k);
        }
    }

    const T& get_min() const {
        return d.size() < 2u ? d[0] : d[1];
    }

    const T& get_max() const {
        return d[0];
    }

    int size() const { return d.size(); }

    bool empty() const { return d.empty(); }

    void make_heap() {
        for (int i = d.size(); i--; ) {
            if (i & 1 && d[i - 1] < d[i]) swap(d[i - 1], d[i]);
            int k = down(i);
            up(k, i);
        }
    }

    inline int parent(int k) const {
        return ((k >> 1) - 1)&~1;
    }

    int down(int k) {
        int n = d.size();
        if (k & 1) { // min heap
            while (2 * k + 1 < n) {
                int c = 2 * k + 3;
                if (n <= c || d[c - 2] < d[c]) c -= 2;
                if (c < n && d[c] < d[k]) { swap(d[k], d[c]); k = c; }
                else break;
            }
        }
        else { // max heap
            while (2 * k + 2 < n) {
                int c = 2 * k + 4;
                if (n <= c || d[c] < d[c - 2]) c -= 2;
                if (c < n && d[k] < d[c]) { swap(d[k], d[c]); k = c; }
                else break;
            }
        }
        return k;
    }

    int up(int k, int root = 1) {
        if ((k | 1) < (int)d.size() && d[k&~1] < d[k | 1]) {
            swap(d[k&~1], d[k | 1]);
            k ^= 1;
        }

        int p;
        while (root < k && d[p = parent(k)] < d[k]) { // max heap
            swap(d[p], d[k]);
            k = p;
        }
        while (root < k && d[k] < d[p = parent(k) | 1]) { // min heap
            swap(d[p], d[k]);
            k = p;
        }
        return k;
    }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
int N, M;
vector<pair<int, int>> v;
//---------------------------------------------------------------------------------------------------
int get() {
    int d; cin >> d;
    string s; cin >> s;
    int h = (s[0] - '0') * 10 + s[1] - '0';
    int m = (s[3] - '0') * 10 + s[4] - '0';
    return d * 24 * 60 + h * 60 + m;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, M) {
        int s = get(), t = get();
        v.push_back({ s, t });
    }
    sort(v.begin(), v.end());

    PriorityQueue<int> que;

    int ans = 0;
    fore(p, v) {
        int s = p.first;
        int t = p.second;

        while (!que.empty() && que.get_min() < s) que.pop_min();
        if (que.size() == N) {
            if (t < que.get_max()) {
                que.pop_max();
                que.push(t);
            }
            continue;
        }

        que.push(t);
        ans++;
    }
    cout << ans << endl;
}
0