結果

問題 No.2615 ペアの作り方
ユーザー tentententen
提出日時 2024-01-29 19:14:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 651 ms / 2,000 ms
コード長 1,970 bytes
コンパイル時間 2,994 ms
コンパイル使用メモリ 92,036 KB
実行使用メモリ 71,916 KB
最終ジャッジ日時 2024-01-29 19:15:07
合計ジャッジ時間 9,213 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
55,144 KB
testcase_01 AC 82 ms
55,144 KB
testcase_02 AC 90 ms
55,136 KB
testcase_03 AC 82 ms
55,144 KB
testcase_04 AC 82 ms
55,128 KB
testcase_05 AC 82 ms
55,140 KB
testcase_06 AC 80 ms
55,128 KB
testcase_07 AC 81 ms
55,152 KB
testcase_08 AC 81 ms
55,144 KB
testcase_09 AC 105 ms
56,064 KB
testcase_10 AC 105 ms
56,028 KB
testcase_11 AC 107 ms
56,040 KB
testcase_12 AC 121 ms
54,040 KB
testcase_13 AC 109 ms
56,296 KB
testcase_14 AC 105 ms
56,292 KB
testcase_15 AC 573 ms
70,848 KB
testcase_16 AC 533 ms
71,916 KB
testcase_17 AC 536 ms
70,860 KB
testcase_18 AC 651 ms
71,248 KB
testcase_19 AC 562 ms
70,852 KB
testcase_20 AC 584 ms
70,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        PriorityQueue<Long> queue = IntStream.range(0, n * 2)
            .mapToObj(i -> sc.nextLong() * 2 + (i >= n ? 1 : 0))
            .collect(Collectors.toCollection(PriorityQueue::new));
        long count = IntStream.range(0, n)
            .mapToLong(i -> queue.poll() % 2)
            .sum();
        System.out.println(getFact(count) * getFact(n - count) % MOD);
    }
    
    static long getFact(long x) {
        return LongStream.rangeClosed(1, x)
            .reduce(1, (a, b) -> (a * b) % MOD);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0