結果

問題 No.674 n連勤
ユーザー htensaihtensai
提出日時 2019-11-12 09:53:21
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,089 bytes
コンパイル時間 2,468 ms
コンパイル使用メモリ 81,056 KB
実行使用メモリ 79,892 KB
最終ジャッジ日時 2023-10-17 17:57:29
合計ジャッジ時間 10,836 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,456 KB
testcase_01 AC 133 ms
57,520 KB
testcase_02 AC 134 ms
57,636 KB
testcase_03 AC 133 ms
57,492 KB
testcase_04 AC 134 ms
57,592 KB
testcase_05 AC 137 ms
57,536 KB
testcase_06 AC 135 ms
57,612 KB
testcase_07 AC 134 ms
57,428 KB
testcase_08 AC 130 ms
57,464 KB
testcase_09 AC 132 ms
57,640 KB
testcase_10 AC 131 ms
57,540 KB
testcase_11 AC 247 ms
60,856 KB
testcase_12 AC 307 ms
60,804 KB
testcase_13 AC 570 ms
64,376 KB
testcase_14 AC 551 ms
61,272 KB
testcase_15 AC 554 ms
62,344 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
		PriorityQueue<Work> queue = new PriorityQueue<>();
		PriorityQueue<Work> next = new PriorityQueue<>();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    queue.add(new Work(sc.nextLong(), sc.nextLong()));
		    Work prev = queue.poll();
		    long max = prev.getCount();
		    while (queue.size() > 0) {
		        Work x = queue.poll();
		        if (prev.end >= x.start - 1) {
		            prev.add(x);
		        } else {
		            next.add(prev);
		            prev = x;
		        }
		        max = Math.max(max, prev.getCount());
		    }
		    sb.append(max).append("\n");
		    next.add(prev);
		    PriorityQueue<Work> tmp = next;
		    next = queue;
		    queue = tmp;
		}
		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 String toString() {
           return "start:" + start + " end:" + end;
       }
   }
 }
0