結果
問題 | No.674 n連勤 |
ユーザー | tenten |
提出日時 | 2021-12-06 14:09:43 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 296 ms / 2,000 ms |
コード長 | 1,838 bytes |
コンパイル時間 | 3,145 ms |
コンパイル使用メモリ | 77,504 KB |
実行使用メモリ | 59,104 KB |
最終ジャッジ日時 | 2023-09-21 15:17:56 |
合計ジャッジ時間 | 6,521 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
49,444 KB |
testcase_01 | AC | 41 ms
49,396 KB |
testcase_02 | AC | 42 ms
49,684 KB |
testcase_03 | AC | 42 ms
49,544 KB |
testcase_04 | AC | 42 ms
49,384 KB |
testcase_05 | AC | 43 ms
49,356 KB |
testcase_06 | AC | 43 ms
49,336 KB |
testcase_07 | AC | 43 ms
49,348 KB |
testcase_08 | AC | 42 ms
49,352 KB |
testcase_09 | AC | 42 ms
49,512 KB |
testcase_10 | AC | 42 ms
49,456 KB |
testcase_11 | AC | 124 ms
52,696 KB |
testcase_12 | AC | 132 ms
52,896 KB |
testcase_13 | AC | 259 ms
55,960 KB |
testcase_14 | AC | 244 ms
55,988 KB |
testcase_15 | AC | 230 ms
56,308 KB |
testcase_16 | AC | 296 ms
59,104 KB |
testcase_17 | AC | 296 ms
58,952 KB |
testcase_18 | AC | 287 ms
57,416 KB |
testcase_19 | AC | 249 ms
56,056 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long d = sc.nextLong(); int n = sc.nextInt(); TreeMap<Long, Long> days = new TreeMap<>(); StringBuilder sb = new StringBuilder(); long max = 0; for (int i = 0; i < n; i++) { long left = sc.nextLong(); long right = sc.nextLong(); Long prev = days.floorKey(left); if (prev != null && days.get(prev) >= left - 1) { left = prev; right = Math.max(right, days.get(prev)); } days.put(left, right); Long next; while ((next = days.higherKey(left)) != null) { if (right + 1 < next) { break; } right = Math.max(right, days.get(next)); days.put(left, right); days.remove(next); } max = Math.max(max, right - left + 1); sb.append(max).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }