結果

問題 No.243 出席番号(2)
ユーザー tsutajtsutaj
提出日時 2018-10-14 18:20:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 731 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 64,632 KB
実行使用メモリ 120,448 KB
最終ジャッジ日時 2024-04-20 20:17:57
合計ジャッジ時間 6,183 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 23 ms
11,648 KB
testcase_04 AC 22 ms
11,392 KB
testcase_05 AC 21 ms
11,520 KB
testcase_06 AC 21 ms
11,520 KB
testcase_07 AC 22 ms
11,520 KB
testcase_08 AC 69 ms
27,136 KB
testcase_09 AC 70 ms
27,136 KB
testcase_10 AC 70 ms
27,136 KB
testcase_11 AC 71 ms
27,264 KB
testcase_12 AC 74 ms
27,264 KB
testcase_13 AC 147 ms
50,944 KB
testcase_14 AC 145 ms
50,688 KB
testcase_15 AC 144 ms
50,816 KB
testcase_16 AC 145 ms
50,688 KB
testcase_17 AC 149 ms
50,688 KB
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 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
using ll = long long int;
ll dp[5010][5010], cnt[5010], MOD = 1000000007;
int main() {
    int N; cin >> N; dp[0][0] = 1;
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        cnt[val]++;
    }
    for(int i=0; i<N; i++) {
        for(int k=0; k<=i; k++) {
            (dp[i+1][k  ] += dp[i][k]         ) %= MOD;
            (dp[i+1][k+1] += dp[i][k] * cnt[i]) %= MOD;
        }
    }
    ll fact = 1, ans = 0, cnt = 0;
    for(int i=N; i>=0; i--) {
        ll val = dp[N][i] * fact % MOD;
        if(i % 2 == 0) ans = (ans + val      ) % MOD;
        else           ans = (ans - val + MOD) % MOD;
        (fact *= (++cnt)) %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0