結果

問題 No.580 旅館の予約計画
ユーザー 👑 horiesinitihoriesiniti
提出日時 2017-10-06 14:10:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,037 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 74,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 17:26:59
合計ジャッジ時間 2,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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