結果

問題 No.2615 ペアの作り方
ユーザー ks2mks2m
提出日時 2024-01-26 21:27:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 77,976 KB
実行使用メモリ 71,116 KB
最終ジャッジ日時 2024-01-26 21:27:35
合計ジャッジ時間 6,803 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
54,116 KB
testcase_01 AC 55 ms
54,228 KB
testcase_02 AC 56 ms
54,136 KB
testcase_03 AC 55 ms
54,116 KB
testcase_04 AC 55 ms
54,104 KB
testcase_05 AC 56 ms
54,116 KB
testcase_06 AC 54 ms
54,112 KB
testcase_07 AC 56 ms
54,116 KB
testcase_08 AC 54 ms
54,120 KB
testcase_09 AC 72 ms
54,996 KB
testcase_10 AC 83 ms
54,868 KB
testcase_11 AC 82 ms
54,856 KB
testcase_12 AC 76 ms
54,888 KB
testcase_13 AC 85 ms
54,892 KB
testcase_14 AC 85 ms
54,872 KB
testcase_15 AC 395 ms
71,036 KB
testcase_16 AC 376 ms
70,472 KB
testcase_17 AC 398 ms
69,140 KB
testcase_18 AC 377 ms
68,780 KB
testcase_19 AC 412 ms
71,116 KB
testcase_20 AC 383 ms
70,700 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());
		String[] sa = br.readLine().split(" ");
		int[] x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] y = new int[n];
		for (int i = 0; i < n; i++) {
			y[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.sort(x);
		Arrays.sort(y);
		int ix = 0;
		int iy = 0;
		int cx = 0;
		int cy = 0;
		while (cx + cy < n) {
			if (x[ix] < y[iy]) {
				cx++;
				ix++;
			} else {
				cy++;
				iy++;
			}
		}

		int mod = 998244353;
		long[] p = new long[n + 1];
		p[0] = 1;
		for (int i = 1; i < p.length; i++) {
			p[i] = p[i - 1] * i % mod;
		}

		long ans = p[cx] * p[cy] % mod;
		System.out.println(ans);
	}
}
0