結果

問題 No.580 旅館の予約計画
ユーザー horiesiniti
提出日時 2017-10-06 14:10:21
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,037 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 851 ms
コンパイル使用メモリ 98,680 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-15 17:25:58
合計ジャッジ時間 2,108 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>
#include<queue>
#include<map>
#include<iostream>

struct E{
	int i,o;
	bool operator<(const E& e1)const{
		if(i!=e1.i)return i>e1.i;
		return o>e1.o;
	}
};



int main(){
	std::priority_queue<E> pq;
	std::map<int,int> ms;
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int d1,d2,h1,h2,m1,m2;
		scanf("%d %d:%d %d %d:%d",&d1,&h1,&m1,&d2,&h2,&m2);
		E e1;
		e1.i=d1*10000+h1*100+m1;
		e1.o=d2*10000+h2*100+m2;
		pq.push(e1);
		//std::cout<<d1<<" "<<h1<<" "<<m1<<" "<<d2<<" "<<h2<<" "<<m2<<"\n";
	}
	int count=0,ans=0;
	while(pq.empty()==false){
		E e1=pq.top();
		pq.pop();
		std::map<int,int>::iterator it=ms.begin();
		while((it!=ms.end())&&((*it).first<e1.i)){
			int add=(*it).second;
			count-=add;
			ans+=add;
			ms.erase(it);
			it=ms.begin();
		}
		
		if(count>=n){
			ms[e1.o]++;
			count++;
			if(count>n){
				it=ms.end();
				it--;
				(*it).second--;
				if((*it).second<1){
					ms.erase(it);
				}
				count--;
			}
		}else{
			count++;
			ms[e1.o]++;
		}
	}
	ans+=count;
	printf("%d\n",ans);
}
0