結果
問題 | No.580 旅館の予約計画 |
ユーザー | tenten |
提出日時 | 2020-09-07 20:20:27 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 243 ms / 2,000 ms |
コード長 | 2,485 bytes |
コンパイル時間 | 2,859 ms |
コンパイル使用メモリ | 79,428 KB |
実行使用メモリ | 46,152 KB |
最終ジャッジ日時 | 2024-11-29 11:16:58 |
合計ジャッジ時間 | 11,822 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 118 ms
40,052 KB |
testcase_01 | AC | 128 ms
41,228 KB |
testcase_02 | AC | 137 ms
41,280 KB |
testcase_03 | AC | 142 ms
41,700 KB |
testcase_04 | AC | 146 ms
41,484 KB |
testcase_05 | AC | 150 ms
41,652 KB |
testcase_06 | AC | 172 ms
41,668 KB |
testcase_07 | AC | 159 ms
41,984 KB |
testcase_08 | AC | 168 ms
41,908 KB |
testcase_09 | AC | 191 ms
42,472 KB |
testcase_10 | AC | 181 ms
42,104 KB |
testcase_11 | AC | 184 ms
42,112 KB |
testcase_12 | AC | 197 ms
43,324 KB |
testcase_13 | AC | 187 ms
42,660 KB |
testcase_14 | AC | 216 ms
43,508 KB |
testcase_15 | AC | 240 ms
45,732 KB |
testcase_16 | AC | 238 ms
45,052 KB |
testcase_17 | AC | 240 ms
45,664 KB |
testcase_18 | AC | 243 ms
45,308 KB |
testcase_19 | AC | 242 ms
45,408 KB |
testcase_20 | AC | 242 ms
45,556 KB |
testcase_21 | AC | 240 ms
45,112 KB |
testcase_22 | AC | 236 ms
46,152 KB |
testcase_23 | AC | 237 ms
45,716 KB |
testcase_24 | AC | 242 ms
45,408 KB |
testcase_25 | AC | 241 ms
45,748 KB |
testcase_26 | AC | 145 ms
41,680 KB |
testcase_27 | AC | 143 ms
41,556 KB |
testcase_28 | AC | 147 ms
41,404 KB |
testcase_29 | AC | 145 ms
41,688 KB |
testcase_30 | AC | 233 ms
45,840 KB |
testcase_31 | AC | 238 ms
45,892 KB |
testcase_32 | AC | 243 ms
45,600 KB |
testcase_33 | AC | 237 ms
45,544 KB |
testcase_34 | AC | 236 ms
45,872 KB |
testcase_35 | AC | 131 ms
41,268 KB |
ソースコード
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; } } }