結果

問題 No.580 旅館の予約計画
ユーザー uafr_csuafr_cs
提出日時 2017-10-30 20:22:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 1,989 bytes
コンパイル時間 2,231 ms
コンパイル使用メモリ 75,076 KB
実行使用メモリ 60,920 KB
最終ジャッジ日時 2023-08-14 13:20:40
合計ジャッジ時間 10,445 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,844 KB
testcase_01 AC 124 ms
55,732 KB
testcase_02 AC 128 ms
55,652 KB
testcase_03 AC 135 ms
55,776 KB
testcase_04 AC 138 ms
56,024 KB
testcase_05 AC 137 ms
56,028 KB
testcase_06 AC 159 ms
55,680 KB
testcase_07 AC 150 ms
55,828 KB
testcase_08 AC 145 ms
53,544 KB
testcase_09 AC 161 ms
56,376 KB
testcase_10 AC 157 ms
56,172 KB
testcase_11 AC 172 ms
56,192 KB
testcase_12 AC 179 ms
57,020 KB
testcase_13 AC 181 ms
55,928 KB
testcase_14 AC 201 ms
59,944 KB
testcase_15 AC 221 ms
60,480 KB
testcase_16 AC 218 ms
60,328 KB
testcase_17 AC 213 ms
60,360 KB
testcase_18 AC 221 ms
60,920 KB
testcase_19 AC 218 ms
58,936 KB
testcase_20 AC 217 ms
60,260 KB
testcase_21 AC 221 ms
59,632 KB
testcase_22 AC 218 ms
60,336 KB
testcase_23 AC 204 ms
60,092 KB
testcase_24 AC 216 ms
59,936 KB
testcase_25 AC 215 ms
60,320 KB
testcase_26 AC 142 ms
56,228 KB
testcase_27 AC 139 ms
55,524 KB
testcase_28 AC 135 ms
56,292 KB
testcase_29 AC 138 ms
55,612 KB
testcase_30 AC 214 ms
59,856 KB
testcase_31 AC 220 ms
60,600 KB
testcase_32 AC 219 ms
59,820 KB
testcase_33 AC 219 ms
60,252 KB
testcase_34 AC 217 ms
59,260 KB
testcase_35 AC 133 ms
55,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static class Range implements Comparable<Range>{
		int begin, end;
		
		public Range(int begin, int end){
			this.begin = begin;
			this.end = end;
		}
		
		public int compareTo(Range arg0){
			if(Integer.compare(this.end, arg0.end) != 0){
				return Integer.compare(this.end, arg0.end);
			}else{
				return Integer.compare(this.begin, arg0.begin);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int m = sc.nextInt();
		
		Range[] range = new Range[m];
		for(int i = 0; i < m; i++){
			final int d_in = sc.nextInt();
			final String[] hhmm_in = sc.next().split(":");
			final int hh_in = Integer.parseInt(hhmm_in[0]);
			final int mm_in = Integer.parseInt(hhmm_in[1]);
			
			final int d_out = sc.nextInt();
			final String[] hhmm_out = sc.next().split(":");
			final int hh_out = Integer.parseInt(hhmm_out[0]);
			final int mm_out = Integer.parseInt(hhmm_out[1]);
			
			final int checkin  = 60 * ((24 * d_in)  + hh_in)  + mm_in;
			final int checkout = 60 * ((24 * d_out) + hh_out) + mm_out;
			
			range[i] = new Range(checkin, checkout + 1);
		}
		
		Arrays.sort(range);
		
		int answer = 0;
		int[] checkout_time = new int[n];
		for(int i = 0; i < m; i++){
			final int begin = range[i].begin;
			final int end = range[i].end;
			
			int latest_time = -1;
			int latest_pos = -1;
			for(int j = 0; j < n; j++){
				if(checkout_time[j] <= begin){
					if(latest_time < checkout_time[j]){
						latest_time = checkout_time[j];
						latest_pos = j;
					}
				}
			}	
			
			if(latest_pos >= 0){
				checkout_time[latest_pos] = end;
				answer++;
			}
			
			//System.out.println(begin + " " + end);
			//System.out.println(Arrays.toString(checkout_time));
		}
		
		System.out.println(answer);
		
	}
}
0