結果

問題 No.580 旅館の予約計画
ユーザー tentententen
提出日時 2020-09-07 20:20:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 2,485 bytes
コンパイル時間 3,220 ms
コンパイル使用メモリ 75,044 KB
実行使用メモリ 61,152 KB
最終ジャッジ日時 2023-08-19 17:08:01
合計ジャッジ時間 12,527 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,520 KB
testcase_01 AC 133 ms
55,800 KB
testcase_02 AC 136 ms
56,056 KB
testcase_03 AC 143 ms
56,544 KB
testcase_04 AC 148 ms
55,900 KB
testcase_05 AC 150 ms
55,964 KB
testcase_06 AC 161 ms
55,868 KB
testcase_07 AC 163 ms
55,920 KB
testcase_08 AC 175 ms
55,896 KB
testcase_09 AC 198 ms
57,096 KB
testcase_10 AC 195 ms
57,076 KB
testcase_11 AC 197 ms
57,208 KB
testcase_12 AC 214 ms
57,460 KB
testcase_13 AC 203 ms
57,420 KB
testcase_14 AC 224 ms
59,688 KB
testcase_15 AC 256 ms
61,152 KB
testcase_16 AC 251 ms
60,924 KB
testcase_17 AC 241 ms
60,080 KB
testcase_18 AC 252 ms
60,620 KB
testcase_19 AC 248 ms
60,620 KB
testcase_20 AC 248 ms
60,488 KB
testcase_21 AC 249 ms
60,124 KB
testcase_22 AC 247 ms
60,016 KB
testcase_23 AC 253 ms
60,692 KB
testcase_24 AC 248 ms
60,464 KB
testcase_25 AC 247 ms
60,600 KB
testcase_26 AC 150 ms
56,064 KB
testcase_27 AC 156 ms
56,236 KB
testcase_28 AC 153 ms
55,788 KB
testcase_29 AC 156 ms
56,052 KB
testcase_30 AC 253 ms
61,060 KB
testcase_31 AC 240 ms
60,564 KB
testcase_32 AC 243 ms
60,420 KB
testcase_33 AC 245 ms
61,052 KB
testcase_34 AC 246 ms
60,420 KB
testcase_35 AC 144 ms
55,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	PriorityQueue<Reserve> queue = new PriorityQueue<>();
    	for (int i = 0; i < m; i++) {
    	    queue.add(new Reserve(i, sc.nextInt(), sc.next(), sc.nextInt(), sc.next()));
    	}
    	int outBound = 0;
    	TreeSet<Remain> remains = new TreeSet<>();
    	while (queue.size() > 0) {
    	    Reserve r = queue.poll();
    	    while (remains.size() > 0 && remains.first().time < r.start) {
    	        remains.remove(remains.pollFirst());
    	    }
    	    remains.add(new Remain(r));
    	    while (remains.size() > n) {
    	        remains.pollLast();
    	        outBound++;
    	    }
    	}
    	System.out.println(m - outBound);
    }
    
    static class Remain implements Comparable<Remain> {
        int idx;
        int time;
        
        public Remain(int idx, int time) {
            this.idx = idx;
            this.time = time;
        }
        
        public Remain(Reserve r) {
            this(r.idx, r.end);
        }
        
        public int hashCode() {
            return idx;
        }
        
        public int compareTo(Remain another) {
            if (time == another.time) {
                return idx - another.idx;
            } else {
                return time - another.time;
            }
        }
        
        public boolean equals(Object o) {
            Remain r = (Remain) o;
            return idx == r.idx;
        }
    }
    
    static class Reserve implements Comparable<Reserve> {
        int idx;
        int start;
        int end;
        
        public Reserve(int idx, int start, int end) {
            this.idx = idx;
            this.start = start;
            this.end = end;
        }
        
        public Reserve(int idx, int startDay, String startTime, int endDay, String endTime) {
            this(idx, getMinute(startDay, startTime), getMinute(endDay, endTime));
        }
        
        static int getMinute(int day, String time) {
            return (day - 2) * 24 * 60 + timeToMinute(time);
        }
        
        static int timeToMinute(String time) {
            String[] arr = time.split(":", 2);
            return Integer.parseInt(arr[0]) * 60 + Integer.parseInt(arr[1]);
        }
        
        public int compareTo(Reserve another) {
            return start - another.start;
        }
    }
}
0