結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 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 1 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 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 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>
class HogloidHeap {
private:
    std::size_t sz;
    std::priority_queue<T> g, gd;
    std::priority_queue<T, std::vector<T>, std::greater<T> > l, ld;
    void flush_min() {
        while (!ld.empty() && l.top() == ld.top()) {
            l.pop();
            ld.pop();
        }
    }
    void flush_max() {
        while (!gd.empty() && g.top() == gd.top()) {
            g.pop();
            gd.pop();
        }
    }

public:
    HogloidHeap() : sz(0) {}
    bool empty() const { return size() == 0; }
    std::size_t size() const { return sz; }
    const T &min() {
        flush_min();
        return l.top();
    }
    const T &max() {
        flush_max();
        return g.top();
    }
    void push(const T &v) {
        l.push(v);
        g.push(v);
        ++sz;
    }
    template <class... Args>
    void emplace(Args &&... args) {
        l.emplace(std::forward<Args>(args)...);
        g.emplace(std::forward<Args>(args)...);
        ++sz;
    }
    void pop_min() {
        flush_min();
        gd.emplace(l.top());
        l.pop();
        --sz;
    }
    void pop_max() {
        flush_max();
        ld.emplace(g.top());
        g.pop();
        --sz;
    }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  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());

    HogloidHeap<int> que;

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

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

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