結果

問題 No.580 旅館の予約計画
ユーザー Pachicobue
提出日時 2017-10-23 04:17:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,204 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 177,832 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-21 15:00:43
合計ジャッジ時間 2,732 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

struct Reservation {
    int start;
    int end;
    bool operator<(const Reservation& r) const
    {
        //        return start < r.start;
        return end < r.end;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    constexpr int DAY = 1440;
    constexpr int HOUR = 60;
    vector<Reservation> res;
    for (int i = 0; i < m; i++) {
        int d;
        cin >> d;
        string s1;
        cin >> s1;
        const int start = d * DAY + stoi(s1.substr(0, 2)) * HOUR + stoi(s1.substr(3, 2));
        int o;
        cin >> o;
        string s2;
        cin >> s2;
        const int end = o * DAY + stoi(s2.substr(0, 2)) * HOUR + stoi(s2.substr(3, 2)) + 1;
        res.push_back(Reservation{start, end});
    }
    sort(res.begin(), res.end());
    //    show(res);
    vector<bool> used(m, false);
    vector<int> end(n, 0);
    for (int i = 0; i < m; i++) {
        if ((not used[i])) {
            int maxj = -1;
            int maxi = 0;
            for (int j = 0; j < n; j++) {
                if (end[j] <= res[i].start) {
                    if (maxi <= end[j]) {
                        maxi = end[j];
                        maxj = j;
                    }
                }
            }
            if (maxj != -1) {
                used[i] = true;
                end[maxj] = res[i].end;
            }
        }
    }
    cerr << endl;
    int num = 0;
    for (int i = 0; i < m; i++) {
        if (used[i]) {
            num++;
        }
    }
    cout << num << endl;
}
0