結果

問題 No.580 旅館の予約計画
ユーザー 37zigen37zigen
提出日時 2017-10-22 23:55:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,884 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 46,848 KB
最終ジャッジ日時 2024-05-01 10:42:09
合計ジャッジ時間 10,099 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
41,336 KB
testcase_01 AC 129 ms
41,348 KB
testcase_02 AC 136 ms
41,428 KB
testcase_03 AC 143 ms
41,688 KB
testcase_04 AC 137 ms
42,080 KB
testcase_05 AC 146 ms
41,724 KB
testcase_06 AC 160 ms
42,360 KB
testcase_07 AC 139 ms
41,984 KB
testcase_08 AC 158 ms
42,016 KB
testcase_09 AC 166 ms
42,712 KB
testcase_10 AC 177 ms
42,796 KB
testcase_11 AC 184 ms
43,080 KB
testcase_12 AC 196 ms
43,440 KB
testcase_13 AC 179 ms
43,036 KB
testcase_14 AC 207 ms
44,228 KB
testcase_15 AC 239 ms
46,088 KB
testcase_16 AC 225 ms
45,560 KB
testcase_17 AC 236 ms
45,536 KB
testcase_18 AC 236 ms
45,836 KB
testcase_19 AC 241 ms
46,848 KB
testcase_20 AC 230 ms
45,812 KB
testcase_21 AC 229 ms
45,872 KB
testcase_22 AC 225 ms
46,128 KB
testcase_23 AC 231 ms
45,684 KB
testcase_24 AC 231 ms
46,368 KB
testcase_25 AC 234 ms
46,344 KB
testcase_26 AC 144 ms
41,948 KB
testcase_27 AC 143 ms
41,764 KB
testcase_28 AC 143 ms
41,628 KB
testcase_29 AC 144 ms
41,800 KB
testcase_30 AC 233 ms
46,044 KB
testcase_31 AC 232 ms
45,960 KB
testcase_32 AC 220 ms
46,108 KB
testcase_33 AC 240 ms
45,900 KB
testcase_34 AC 227 ms
45,804 KB
testcase_35 AC 135 ms
41,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

class Solution {
	public static void main(String[] args) {
		new Solution().run();
	}

	class Edge implements Comparable<Edge> {
		int src;
		int dst;

		public Edge(int src, int dst) {
			this.src = src;
			this.dst = dst;
		}

		@Override
		public int compareTo(Edge o) {
			return Integer.compare(src, o.src);
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] v = new int[m][2];
		for (int i = 0; i < m; ++i) {
			int v1 = sc.nextInt();
			String[] s1 = sc.next().split(":");
			int v2 = sc.nextInt();
			String[] s2 = sc.next().split(":");
			int src = v1 * 10000 + new Integer(s1[0]) * 100 + new Integer(s1[1]);
			int dst = v2 * 10000 + new Integer(s2[0]) * 100 + new Integer(s2[1]);
			v[i][0] = src;
			v[i][1] = dst;
		}

		Arrays.sort(v, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[0], o2[0]);
			}
		});
		int ans = 0;
		int cnt = 0;
		ArrayList<Edge> pending = new ArrayList<>();
		for (int i = 0; i < m; ++i) {
			int src = v[i][0];
			int dst = v[i][1];
			pending.add(new Edge(v[i][0], v[i][1]));
			++cnt;
			if (cnt <= n) {
				continue;
			} else {
				Edge tmp = null;
				for (int j = 0; j < pending.size(); ++j) {
					if (pending.get(j).dst < src) {
						pending.remove(j);
						--j;
						--cnt;
						++ans;
					}
					if (j >= 0 && (tmp == null || tmp.dst < pending.get(j).dst)) {
						tmp = pending.get(j);
					}
				}
				if (cnt > n) {
					pending.remove(tmp);
					--cnt;
					if (cnt > n)
						throw new AssertionError();
				}
			}
		}
		ans += cnt;
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0