結果

問題 No.580 旅館の予約計画
ユーザー htensaihtensai
提出日時 2020-02-17 16:26:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 2,051 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 78,848 KB
実行使用メモリ 40,308 KB
最終ジャッジ日時 2024-04-16 03:50:56
合計ジャッジ時間 6,784 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,148 KB
testcase_01 AC 52 ms
37,048 KB
testcase_02 AC 53 ms
37,220 KB
testcase_03 AC 54 ms
37,264 KB
testcase_04 AC 54 ms
37,180 KB
testcase_05 AC 55 ms
36,808 KB
testcase_06 AC 57 ms
37,188 KB
testcase_07 AC 58 ms
37,108 KB
testcase_08 AC 57 ms
37,204 KB
testcase_09 AC 58 ms
37,140 KB
testcase_10 AC 59 ms
37,408 KB
testcase_11 AC 59 ms
37,460 KB
testcase_12 AC 84 ms
38,316 KB
testcase_13 AC 63 ms
37,592 KB
testcase_14 AC 99 ms
39,080 KB
testcase_15 AC 123 ms
40,012 KB
testcase_16 AC 124 ms
40,160 KB
testcase_17 AC 114 ms
40,024 KB
testcase_18 AC 122 ms
40,084 KB
testcase_19 AC 107 ms
39,820 KB
testcase_20 AC 120 ms
39,988 KB
testcase_21 AC 115 ms
39,792 KB
testcase_22 AC 121 ms
39,940 KB
testcase_23 AC 108 ms
39,900 KB
testcase_24 AC 122 ms
40,024 KB
testcase_25 AC 120 ms
39,708 KB
testcase_26 AC 54 ms
36,980 KB
testcase_27 AC 54 ms
37,160 KB
testcase_28 AC 54 ms
37,112 KB
testcase_29 AC 54 ms
37,280 KB
testcase_30 AC 124 ms
39,748 KB
testcase_31 AC 112 ms
40,156 KB
testcase_32 AC 122 ms
40,096 KB
testcase_33 AC 125 ms
40,308 KB
testcase_34 AC 122 ms
40,176 KB
testcase_35 AC 55 ms
37,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String[] first = br.readLine().split(" ", 2);
		int m = Integer.parseInt(first[0]);
		int n = Integer.parseInt(first[1]);
		ArrayList<Customer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    list.add(new Customer(i, br.readLine()));
		}
		Collections.sort(list, new Comparator<Customer>() {
		    public int compare(Customer c1, Customer c2) {
		        if (c1.left == c2.left) {
		            return c1.right - c2.right;
		        } else {
		            return c1.left - c2.left;
		        }
		    }
		});
		TreeSet<Customer> stays = new TreeSet<>();
		int count = 0;
		for (Customer c : list) {
		    while (stays.size() > 0 && stays.first().right < c.left) {
		        stays.pollFirst();
		    }
		    stays.add(c);
		    if (stays.size() > m) {
		        count++;
		        stays.pollLast();
		    }
		}
		System.out.println(n - count);
    }
    
    static class Customer implements Comparable<Customer> {
        int idx;
        int left;
        int right;
        
        public Customer(int idx, String line) {
            this.idx = idx;
            String[] args = line.split(" ", 4);
            left = Integer.parseInt(args[0]) * 24 * 60;
            String[] in = args[1].split(":", 2);
            left += Integer.parseInt(in[0]) * 60;
            left += Integer.parseInt(in[1]);
            right = Integer.parseInt(args[2]) * 24 * 60;
            String[] out = args[3].split(":", 2);
            right += Integer.parseInt(out[0]) * 60;
            right += Integer.parseInt(out[1]);
        }
        
        public int hashCode() {
            return idx;
        }
        
        public int compareTo(Customer another) {
            if (right == another.right) {
                return idx - another.idx;
            } else {
                return right - another.right;
            }
        }
    }
}
0