結果

問題 No.243 出席番号(2)
ユーザー titiatitia
提出日時 2022-08-09 04:10:46
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 575 ms / 2,000 ms
コード長 750 bytes
コンパイル時間 15,376 ms
コンパイル使用メモリ 435,636 KB
実行使用メモリ 53,684 KB
最終ジャッジ日時 2023-10-19 15:41:47
合計ジャッジ時間 28,364 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 287 ms
51,716 KB
testcase_01 AC 286 ms
51,700 KB
testcase_02 AC 285 ms
51,716 KB
testcase_03 AC 326 ms
52,024 KB
testcase_04 AC 317 ms
51,956 KB
testcase_05 AC 306 ms
51,948 KB
testcase_06 AC 308 ms
51,948 KB
testcase_07 AC 323 ms
52,020 KB
testcase_08 AC 356 ms
52,032 KB
testcase_09 AC 342 ms
52,040 KB
testcase_10 AC 338 ms
52,040 KB
testcase_11 AC 326 ms
51,980 KB
testcase_12 AC 357 ms
52,044 KB
testcase_13 AC 378 ms
52,052 KB
testcase_14 AC 356 ms
52,060 KB
testcase_15 AC 359 ms
52,044 KB
testcase_16 AC 352 ms
52,060 KB
testcase_17 AC 396 ms
52,192 KB
testcase_18 AC 410 ms
52,204 KB
testcase_19 AC 369 ms
52,056 KB
testcase_20 AC 357 ms
52,044 KB
testcase_21 AC 355 ms
52,056 KB
testcase_22 AC 464 ms
52,204 KB
testcase_23 AC 475 ms
53,684 KB
testcase_24 AC 413 ms
53,676 KB
testcase_25 AC 396 ms
53,676 KB
testcase_26 AC 389 ms
53,644 KB
testcase_27 AC 575 ms
53,676 KB
testcase_28 AC 285 ms
51,728 KB
testcase_29 AC 285 ms
51,724 KB
testcase_30 AC 283 ms
51,716 KB
testcase_31 AC 285 ms
51,700 KB
testcase_32 AC 289 ms
51,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
    val mod=1000000007
    val n = readLine()!!.toInt()
    val A = IntArray(n)

    for (i in 0..n-1){
        val x = readLine()!!.toInt()
        if (x<n){
            A[x]+=1
        }
    }

    val DP = LongArray(n+1){0}
    DP[0]=1

    for (v in A){
        if (v==0){
            continue
        }
        for (i in 0..n-1){
            var j=n-1-i
            DP[j+1]=(DP[j+1]+DP[j]*v)%mod
        }
    }

    var ANS=0.toLong()
    var fac=1.toLong()
    for (i in 0..n){
        if (i%2==0){
            ANS+=fac*DP[n-i]
            ANS%=mod}
        else{
            ANS-=fac*DP[n-i]}

        fac=fac*(i+1)%mod}

    if (n%2==1) {
        println((-ANS+mod) % mod)
    }
    else{
        println((ANS+mod)%mod)
    }
}
0