結果

問題 No.580 旅館の予約計画
ユーザー ohreitetsuohreitetsu
提出日時 2017-11-11 20:34:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,747 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 79,964 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-16 07:48:27
合計ジャッジ時間 5,616 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 3 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
void getDateTime(int d,char *t,int &date,int &hour,int &minute)
{
	date=d;
	char *p=strchr(t,':');
	*p='\0';
	hour=atol(t);
	p++;
	minute=atol(p);
}
struct DATE{
	int d;
	int h;
	int m;
	DATE(){
		d=h=m=0;
	}
	DATE(int D,int H,int M){
		d=D;
		h=H;
		m=M;
	}
	bool operator<(DATE &date){
		if (d<date.d){
			return true;
		}else if (d==date.d){
			if (h<date.h){
				return true;
			}else if (h==date.h){
				if (m<date.m){
					return true;
				}
			}
		}
		return false;
	}
	bool operator>(DATE &date){
		if (d>date.d){
			return true;
		}else if (d==date.d){
			if (h>date.h){
				return true;
			}else if (h==date.h){
				if (m>date.m){
					return true;
				}
			}
		}
		return false;
	}
	bool operator==(DATE &date){
		return d==date.d && h==date.h && m==date.m;
	}
	void addMinute(int minute){
		m+=1;
		if (m==60){
			h++;
			m=0;
		}
		if (h==24){
			d++;
			h=0;
		}
	}
};
struct P{
	int id;
	DATE D;
	DATE O;
	P(int ID,DATE d,DATE o){
		id=ID;
		D=d;
		O=o;
	}
	DATE& getD(){
		return D;
	}
	DATE& getO(){
		return O;
	}
	bool operator<(P &p)
	{
		if (O<p.D){
			return true;
		}else{
			return false;
		}
	}
	bool operator==(P &p)
	{
		return D==p.D && O==p.O && id==p.id;
	}
	bool operator>(P &p){
		if (D>p.O){
			return true;
		}
		return false;
	}
};
bool Include(vector<P> &PList,P &p)
{
	int i;
	bool bInsert=true;
	for (i=0;i<PList.size();i++){
		if (PList[i]<p || PList[i]>p){
			continue;
		}else{
			bInsert=false;
			break;
		}
	}
	return bInsert;
}
bool LE(P &l,P &r)
{
	if (l<r){
		return true;
	}else{
		return false;
	}
}
void merge(vector<vector<P>> &PList,int i,int j)
{
	int len1=PList[i].size();
	int len2=PList[j].size();
	if (len1==0 || len2==0){
		return;
	}
	int I,J;
	if (len1>=len2){
		I=i;
		J=j;
	}else{
		I=j;
		J=i;
	}
	for (int y=0;y<PList[J].size();y++){
		if (Include(PList[I],PList[J][y])){
			PList[I].push_back(PList[J][y]);
			PList[J][y].D.d=0;
			PList[J][y].O.d=0;
		}
	}
}
int main(int argc, char* argv[])
{
	int n,m;
	cin>>n>>m;
	int d,o;
	string t1,t2;
	int i,j;
	vector<P> p;
	for (i=0;i<m;i++){
		cin>>d>>t1>>o>>t2;
		int dateD,hourD,minuteD;
		int dateO,hourO,minuteO;
		getDateTime(d,(char*)t1.c_str(),dateD,hourD,minuteD);
		getDateTime(o,(char*)t2.c_str(),dateO,hourO,minuteO);
		p.push_back(P(i+1,DATE(dateD,hourD,minuteD),DATE(dateO,hourO,minuteO)));
	}
	vector<vector<P>> PList(m);
	for (i=0;i<m;i++){
		PList[i].push_back(p[i]);
	}
	for (i=0;i<m;i++){
		for (j=0;j<m;j++){
			if (i!=j){
				if (Include(PList[i],p[j])){
					PList[i].push_back(p[j]);
				}
			}
		}
	}
	///////////////////////
	//for (i=0;i<m;i++){
	//	sort(PList[i].begin(),PList[i].end(),LE);
	//}

	//////////////////////////
	int maxNum=0;
	int index=0;
	vector<int> num;
	for (i=0;i<m;i++){
		int num1=PList[i].size();
		if (maxNum<num1){
			maxNum=num1;
			index=i;
		}
	}
	for (i=0;i<m;i++){
		if (i!=index){
			for (j=0;j<PList[index].size();j++){
				for (int k=0;k<PList[i].size();k++){
					if (PList[i][k]==PList[index][j]){
						PList[i][k].D.d=0;
						PList[i][k].O.d=0;
					}
				}
			}
		}
	}
	vector<vector<P>> PList1(m);
	for (i=0;i<m;i++){
		for (j=0;j<PList[i].size();j++){
			if (PList[i][j].D.d>0){
				PList1[i].push_back(PList[i][j]);
			}
		}
	}
	for (i=0;i<m;i++){
		for (j=0;j<m;j++){
			if (i!=j){
				merge(PList1,i,j);
			}
		}
	}
	for (i=0;i<m;i++){
		PList[i].clear();
		for (j=0;j<PList1[i].size();j++){
			if (PList1[i][j].D.d>0){
				PList[i].push_back(PList1[i][j]);
			}
		}
		num.push_back(PList[i].size());
	}
	sort(num.begin(),num.end(),greater<int>());
	
	int aw=0;
	for (i=0;i<n;i++){
		aw+=num[i];
	}
	cout<<aw<<endl;
	return 0;
}
0