結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,380 KB
testcase_01 AC 37 ms
53,380 KB
testcase_02 AC 37 ms
53,380 KB
testcase_03 MLE -
testcase_04 AC 54 ms
63,756 KB
testcase_05 AC 54 ms
63,756 KB
testcase_06 AC 55 ms
63,756 KB
testcase_07 AC 55 ms
63,756 KB
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 37 ms
53,380 KB
testcase_29 AC 38 ms
53,380 KB
testcase_30 AC 38 ms
53,380 KB
testcase_31 AC 39 ms
53,380 KB
testcase_32 AC 39 ms
53,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

N=int(input())
A=[int(input()) for i in range(N)]
C=[0]*N
for a in A:
    if a<N:
        C[a]+=1

mod=10**9+7

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

for v in C:
    if v==0:
        continue
    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