結果

問題 No.580 旅館の予約計画
ユーザー HaarHaar
提出日時 2020-05-06 00:49:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 212,248 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 18:24:38
合計ジャッジ時間 4,044 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

auto interval_scheduling_k(std::vector<int> l, std::vector<int> r, int k){
  const int N = l.size();

  std::vector<int> ord(N);
  std::iota(ord.begin(), ord.end(), 0);
  std::sort(ord.begin(), ord.end(), [&](int i, int j){return r[i] < r[j];});  

  std::multiset<int> a;
  std::vector<std::pair<int,int>> ret;

  for(int i : ord){
    auto it = a.upper_bound(l[i]);

    if(it != a.begin()){
      it = std::prev(it);
      a.erase(it);
    }

    if((int)a.size() < k){
      a.insert(r[i]);
      ret.emplace_back(l[i], r[i]);
    }
  }
  
  return ret;
}



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

  std::vector<int> l(m), r(m);

  for(int i = 0; i < m; ++i){
    int d; std::cin >> d;
    int h1, m1; std::cin >> h1; std::cin.ignore(); std::cin >> m1;

    int o; std::cin >> o;
    int h2, m2; std::cin >> h2; std::cin.ignore(); std::cin >> m2;

    l[i] = d * 24 * 60 + h1 * 60 + m1;
    r[i] = o * 24 * 60 + h2 * 60 + m2 + 1;
  }

  auto res = interval_scheduling_k(l, r, n);
  std::cout << res.size() << "\n";

  return 0;
}
0