結果

問題 No.243 出席番号(2)
ユーザー titiatitia
提出日時 2022-08-09 03:48:40
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 568 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 76,920 KB
最終ジャッジ日時 2023-10-19 15:23:43
合計ジャッジ時間 3,953 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,612 KB
testcase_01 AC 41 ms
55,612 KB
testcase_02 AC 42 ms
55,612 KB
testcase_03 MLE -
testcase_04 AC 58 ms
63,940 KB
testcase_05 AC 57 ms
63,940 KB
testcase_06 AC 61 ms
63,940 KB
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 AC 42 ms
55,632 KB
testcase_29 AC 43 ms
55,632 KB
testcase_30 AC 42 ms
55,632 KB
testcase_31 AC 42 ms
55,632 KB
testcase_32 AC 43 ms
55,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 包除原理の典型問題
# 解説を見てしまったが、これを解けないのはダメ。

from collections import Counter

N=int(input())
A=[int(input()) for i in range(N)]
C=Counter(A)

mod=10**9+7

DP=[0]*(N+1)
DP[0]=1

for c in C:
    if c<N:
        v=C[c]
        for i in range(N-1,-1,-1):
            DP[i+1]+=DP[i]*v
            DP[i+1]%=mod      
ANS=0
fac=1
for i in range(N+1):
    if i%2==0:
        ANS+=fac*DP[N-i]
    else:
        ANS-=fac*DP[N-i]

    fac=fac*(i+1)%mod

    ANS%=mod

if N%2==1:
    print((-ANS)%mod)
else:
    print(ANS)
0