結果

問題 No.2615 ペアの作り方
ユーザー miya145592miya145592
提出日時 2024-01-26 22:28:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 158,052 KB
最終ジャッジ日時 2024-01-26 22:28:34
合計ジャッジ時間 3,381 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 34 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 35 ms
53,460 KB
testcase_09 AC 40 ms
59,444 KB
testcase_10 AC 40 ms
59,444 KB
testcase_11 AC 39 ms
59,444 KB
testcase_12 AC 39 ms
59,444 KB
testcase_13 AC 39 ms
59,444 KB
testcase_14 AC 40 ms
59,444 KB
testcase_15 AC 195 ms
157,960 KB
testcase_16 AC 195 ms
157,952 KB
testcase_17 AC 190 ms
157,220 KB
testcase_18 AC 197 ms
158,052 KB
testcase_19 AC 192 ms
157,820 KB
testcase_20 AC 192 ms
157,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def nPr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

def nCr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod

import sys
input = sys.stdin.readline
MOD = 998244353
N = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
fact = [1, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )
    fact.append( (fact[-1] * i) % MOD )

S = []
for x in X:
    S.append(x)
for y in Y:
    S.append(y)
S.sort()
X = set(X)
Y = set(Y)
xcnt = 0
ycnt = 0
for i in range(N):
    s = S[i]
    if s in X:
        xcnt+=1
    else:
        ycnt+=1
ans = fact[xcnt] * fact[ycnt] % MOD
print(ans)
0