結果
問題 | No.580 旅館の予約計画 |
ユーザー |
![]() |
提出日時 | 2021-02-17 15:25:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,419 bytes |
コンパイル時間 | 2,384 ms |
コンパイル使用メモリ | 202,000 KB |
最終ジャッジ日時 | 2025-01-18 21:48:57 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d %d:%d %d %d:%d", d, h, m, d + 1, h + 1, m + 1); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) begin(v),end(v)template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }using ll = long long;using pii = pair<int, int>;constexpr ll INF = 1ll<<30;constexpr ll longINF = 1ll<<60;constexpr ll MOD = 1000000007;constexpr bool debug = false;//---------------------------------//int main() {int N, M;cin >> N >> M;vector<int> L(M), R(M);REP(i, M) {int d[2], h[2], m[2];scanf("%d %d:%d %d %d:%d", d, h, m, d + 1, h + 1, m + 1);auto conv = [](int d, int h, int m) {return (d - 2) * 24 * 60 + h * 60 + m;};L[i] = conv(d[0], h[0], m[0]);R[i] = conv(d[1], h[1], m[1]) + 1;}vector<int> ord(M);iota(ALL(ord), 0);sort(ALL(ord), [&](int i, int j) { return L[i] < L[j]; });multiset<int> ms; // 最小の RREP(i, N) ms.insert(INF);int ans = 0;for (int i : ord) {while (!ms.empty() && *ms.begin() <= L[i]) {ms.erase(ms.begin());ms.insert(INF);++ans;}if (*--ms.end() > R[i]) {ms.erase(--ms.end());ms.insert(R[i]);}}while (!ms.empty() && *ms.begin() != INF) {ms.erase(ms.begin());++ans;}cout << ans << endl;}