結果

問題 No.580 旅館の予約計画
ユーザー uafr_csuafr_cs
提出日時 2017-10-30 20:22:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 1,989 bytes
コンパイル時間 2,647 ms
コンパイル使用メモリ 79,148 KB
実行使用メモリ 45,648 KB
最終ジャッジ日時 2024-05-02 01:33:25
合計ジャッジ時間 11,647 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
41,188 KB
testcase_01 AC 142 ms
41,312 KB
testcase_02 AC 153 ms
41,352 KB
testcase_03 AC 156 ms
41,344 KB
testcase_04 AC 167 ms
41,616 KB
testcase_05 AC 165 ms
41,552 KB
testcase_06 AC 179 ms
41,428 KB
testcase_07 AC 175 ms
41,500 KB
testcase_08 AC 174 ms
41,444 KB
testcase_09 AC 198 ms
41,608 KB
testcase_10 AC 193 ms
41,676 KB
testcase_11 AC 204 ms
42,296 KB
testcase_12 AC 212 ms
42,940 KB
testcase_13 AC 202 ms
42,644 KB
testcase_14 AC 245 ms
43,640 KB
testcase_15 AC 251 ms
45,348 KB
testcase_16 AC 250 ms
45,188 KB
testcase_17 AC 256 ms
45,372 KB
testcase_18 AC 249 ms
45,152 KB
testcase_19 AC 248 ms
45,268 KB
testcase_20 AC 247 ms
45,252 KB
testcase_21 AC 245 ms
45,240 KB
testcase_22 AC 241 ms
45,312 KB
testcase_23 AC 239 ms
45,648 KB
testcase_24 AC 231 ms
45,384 KB
testcase_25 AC 243 ms
45,372 KB
testcase_26 AC 153 ms
41,424 KB
testcase_27 AC 150 ms
41,236 KB
testcase_28 AC 160 ms
41,500 KB
testcase_29 AC 165 ms
41,440 KB
testcase_30 AC 251 ms
45,428 KB
testcase_31 AC 237 ms
45,060 KB
testcase_32 AC 249 ms
45,572 KB
testcase_33 AC 250 ms
45,068 KB
testcase_34 AC 240 ms
45,068 KB
testcase_35 AC 149 ms
41,208 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