結果
問題 | No.674 n連勤 |
ユーザー | htensai |
提出日時 | 2019-11-12 10:04:28 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 674 ms / 2,000 ms |
コード長 | 2,337 bytes |
コンパイル時間 | 2,923 ms |
コンパイル使用メモリ | 80,168 KB |
実行使用メモリ | 64,596 KB |
最終ジャッジ日時 | 2023-10-17 18:16:14 |
合計ジャッジ時間 | 10,585 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 133 ms
57,460 KB |
testcase_01 | AC | 135 ms
57,096 KB |
testcase_02 | AC | 135 ms
57,596 KB |
testcase_03 | AC | 136 ms
57,396 KB |
testcase_04 | AC | 138 ms
57,720 KB |
testcase_05 | AC | 142 ms
57,436 KB |
testcase_06 | AC | 138 ms
57,620 KB |
testcase_07 | AC | 139 ms
57,444 KB |
testcase_08 | AC | 137 ms
57,384 KB |
testcase_09 | AC | 136 ms
57,472 KB |
testcase_10 | AC | 136 ms
57,620 KB |
testcase_11 | AC | 252 ms
60,460 KB |
testcase_12 | AC | 274 ms
61,796 KB |
testcase_13 | AC | 585 ms
62,132 KB |
testcase_14 | AC | 592 ms
62,364 KB |
testcase_15 | AC | 564 ms
62,056 KB |
testcase_16 | AC | 674 ms
64,376 KB |
testcase_17 | AC | 670 ms
64,596 KB |
testcase_18 | AC | 627 ms
62,560 KB |
testcase_19 | AC | 643 ms
63,092 KB |
ソースコード
import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); long d = sc.nextLong(); int q = sc.nextInt(); TreeSet<Work> set = new TreeSet<>(); StringBuilder sb = new StringBuilder(); long max = 0; for (int i = 0; i < q; i++) { Work tmp = new Work(sc.nextLong(), sc.nextLong()); while (true) { Work before = set.floor(tmp); if (before == null || before.end < tmp.start - 1) { break; } tmp.add(before); set.remove(before); } while (true) { Work after = set.ceiling(tmp); if (after == null || tmp.end < after.start - 1) { break; } tmp.add(after); set.remove(after); } max = Math.max(max, tmp.getCount()); set.add(tmp); sb.append(max).append("\n"); } System.out.print(sb); } static class Work implements Comparable<Work> { long start; long end; public Work(long start, long end) { this.start = start; this.end = end; } public int compareTo(Work another) { if (start == another.start) { if (end == another.end) { return 0; } else if (end < another.end) { return -1; } else { return 1; } } else { if (start == another.start) { return 0; } else if (start < another.start) { return -1; } else { return 1; } } } public long getCount() { return end - start + 1; } public void add(Work another) { start = Math.min(start, another.start); end = Math.max(end, another.end); } public int hashCode() { return (int)start; } public boolean equals(Object o) { Work another = (Work) o; return start == another.start && end == another.end; } public String toString() { return "start:" + start + " end:" + end; } } }