結果

問題 No.2667 Constrained Permutation
ユーザー ks2mks2m
提出日時 2024-03-08 21:54:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 2,998 ms
コンパイル使用メモリ 77,380 KB
実行使用メモリ 62,956 KB
最終ジャッジ日時 2024-03-08 21:55:19
合計ジャッジ時間 22,275 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
54,112 KB
testcase_01 AC 54 ms
54,112 KB
testcase_02 AC 66 ms
54,244 KB
testcase_03 AC 78 ms
54,884 KB
testcase_04 AC 86 ms
55,016 KB
testcase_05 AC 71 ms
54,260 KB
testcase_06 AC 82 ms
54,904 KB
testcase_07 AC 60 ms
54,236 KB
testcase_08 AC 100 ms
55,116 KB
testcase_09 AC 88 ms
55,264 KB
testcase_10 AC 74 ms
54,888 KB
testcase_11 AC 93 ms
55,136 KB
testcase_12 AC 348 ms
59,856 KB
testcase_13 AC 127 ms
56,784 KB
testcase_14 AC 576 ms
62,312 KB
testcase_15 AC 515 ms
62,036 KB
testcase_16 AC 459 ms
62,044 KB
testcase_17 AC 268 ms
61,000 KB
testcase_18 AC 613 ms
61,824 KB
testcase_19 AC 619 ms
62,412 KB
testcase_20 AC 583 ms
62,236 KB
testcase_21 AC 636 ms
62,176 KB
testcase_22 AC 597 ms
62,268 KB
testcase_23 AC 605 ms
62,160 KB
testcase_24 AC 373 ms
61,968 KB
testcase_25 AC 519 ms
61,984 KB
testcase_26 AC 596 ms
62,292 KB
testcase_27 AC 624 ms
61,916 KB
testcase_28 AC 531 ms
62,188 KB
testcase_29 AC 515 ms
61,548 KB
testcase_30 AC 548 ms
60,068 KB
testcase_31 AC 400 ms
61,972 KB
testcase_32 AC 199 ms
59,404 KB
testcase_33 WA -
testcase_34 AC 431 ms
62,132 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 518 ms
60,984 KB
testcase_39 AC 122 ms
56,728 KB
testcase_40 AC 415 ms
61,816 KB
testcase_41 AC 533 ms
62,080 KB
testcase_42 AC 439 ms
62,460 KB
testcase_43 AC 510 ms
61,956 KB
testcase_44 AC 305 ms
61,408 KB
testcase_45 AC 119 ms
56,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] l = new int[n];
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			l[i] = Integer.parseInt(sa[0]);
			r[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		Arrays.sort(l);
		Arrays.sort(r);
		int maxL = 0;
		int minR = 1000000007;
		for (int i = 0; i < n; i++) {
			int i1 = i + 1;
			maxL = Math.max(maxL, l[i] - i1);
			minR = Math.min(minR, r[i] - i1);
		}
		int ans = Math.max(minR - maxL + 1, 0);
		System.out.println(ans);
	}
}
0