結果

問題 No.580 旅館の予約計画
ユーザー fura
提出日時 2020-05-30 10:08:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 2,631 ms
コンパイル使用メモリ 202,812 KB
最終ジャッジ日時 2025-01-10 19:14:27
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int input()’:
main.cpp:15:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         int d,h,m; scanf("%d%d:%d",&d,&h,&m);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:20:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         int k,n; scanf("%d%d",&k,&n);
      |                  ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

template<class T> struct interval{
	T l,r;
	interval(){}
	interval(const T& l,const T& r):l(l),r(r){}
	bool operator<(const interval& I)const{ return make_tuple(r,l)<make_tuple(I.r,I.l); }
};

int input(){
	int d,h,m; scanf("%d%d:%d",&d,&h,&m);
	return 24*60*d+60*h+m;
}

int main(){
	int k,n; scanf("%d%d",&k,&n);
	vector<interval<int>> I(n);
	rep(i,n){
		I[i].l=input();
		I[i].r=input()+1;
	}

	sort(I.begin(),I.end());

	int ans=0,cnt=0;
	priority_queue<int,vector<int>,greater<int>> Q;
	rep(i,n){
		while(!Q.empty() && Q.top()<=I[i].l) Q.pop(), cnt--;
		if(cnt<k){
			Q.emplace(I[i].r);
			ans++;
			cnt++;
		}
	}
	printf("%d\n",ans);

	return 0;
}
0