結果

問題 No.580 旅館の予約計画
ユーザー 👑 horiesinitihoriesiniti
提出日時 2017-10-10 17:20:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,771 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 75,868 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 10:09:06
合計ジャッジ時間 1,713 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%d %d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:23:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |                 scanf("%d %d:%d %d %d:%d",&d1,&h1,&m1,&d2,&h2,&m2);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<queue>
#include<map>
#include<iostream>
 
struct E{
	int i,o;
	bool operator<(const E& e1)const{
		if(o!=e1.o)return o>e1.o;//チェックアウトが速い順に取り出す
		return i<e1.i;
	}
};
 
 
 
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);
		if(e1.i>e1.o){
			printf("err\n");
		}
		//std::cout<<d1<<" "<<h1<<" "<<m1<<" "<<d2<<" "<<h2<<" "<<m2<<"\n";
	}
	int count=0,ans=0;//countは部屋に割り当てた予約数の管理
	while(pq.empty()==false){
		//客をチェックアウトが速い順(同じ場合チェックインが遅い順)に一人ずつ取り出す
		E e1=pq.top();
		pq.pop();
		std::map<int,int>::iterator it=ms.begin();
		//e1より早くチェックアウトする客の予約を確定し答えに集計する
		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]++;
			it=ms.end();
			it--;
			//一人削除
			(*it).second--;
			if((*it).second<1){
				ms.erase(it);
			}
		}else{
			//部屋数より部屋に割り当てた予約数が少ないのでそのまま部屋に割り当てる
			count++;
			ms[e1.o]++;
		}
	}
	ans+=count;
	printf("%d\n",ans);
}
0