結果

問題 No.580 旅館の予約計画
ユーザー 梧桐
提出日時 2026-03-22 21:44:07
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,307 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 767 ms
コンパイル使用メモリ 92,572 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-22 21:44:14
合計ジャッジ時間 6,870 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> PII;

const int N = 110, M = 1010;

int n, m, ans, rooms[N];
PII ti[M];

int main() {
    // freopen("hotel.in", "r", stdin);
    // freopen("hotel.out", "w", stdout);

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; ++i) {
        int d1, d2;
        string s1, s2;
        cin >> d1 >> s1 >> d2 >> s2;
        int h1 = (s1[0] - '0') * 10 + s1[1] - '0';
        int h2 = (s2[0] - '0') * 10 + s2[1] - '0';
        int m1 = (s1[3] - '0') * 10 + s1[4] - '0';
        int m2 = (s2[3] - '0') * 10 + s2[4] - '0';
        ti[i].first = d1 * 1440 + h1 * 60 + m1;
        ti[i].second = d2 * 1440 + h2 * 60 + m2;
    }

    sort(ti + 1, ti + m + 1, [](PII p1, PII p2) {
        return p1.second < p2.second;
    });

    for (int i = 1; i <= m; ++i) {
        int ma = 0, idx = 0;
        for (int j = 1; j <= n; ++j) {
            if (rooms[j] < ti[i].first) {
                if (ma < rooms[j] || rooms[j] == 0) {
                    ma = rooms[j];
                    idx = j;
                }
            }
        }
        if (idx || i == 1) {
            ++ans;
            rooms[idx] = ti[i].second;
        }
    }

    printf("%d\n", ans);

    return 0;
}
0