結果

問題 No.140 みんなで旅行
ユーザー tottoripapertottoripaper
提出日時 2019-03-09 17:32:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 318 ms / 5,000 ms
コード長 829 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 163,860 KB
実行使用メモリ 6,088 KB
最終ジャッジ日時 2023-09-05 19:51:18
合計ジャッジ時間 4,106 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,784 KB
testcase_01 AC 3 ms
5,812 KB
testcase_02 AC 18 ms
5,920 KB
testcase_03 AC 3 ms
5,916 KB
testcase_04 AC 3 ms
5,840 KB
testcase_05 AC 3 ms
5,972 KB
testcase_06 AC 4 ms
5,840 KB
testcase_07 AC 4 ms
6,088 KB
testcase_08 AC 4 ms
5,784 KB
testcase_09 AC 4 ms
5,908 KB
testcase_10 AC 5 ms
5,744 KB
testcase_11 AC 317 ms
5,804 KB
testcase_12 AC 14 ms
5,784 KB
testcase_13 AC 9 ms
5,908 KB
testcase_14 AC 318 ms
5,856 KB
testcase_15 AC 315 ms
5,784 KB
testcase_16 AC 97 ms
5,816 KB
testcase_17 AC 45 ms
5,968 KB
testcase_18 AC 222 ms
5,880 KB
testcase_19 AC 255 ms
6,040 KB
testcase_20 AC 37 ms
5,844 KB
testcase_21 AC 7 ms
5,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr ll MOD = 1'000'000'007;
int N;
ll dp[556][556];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    ll c = 0;

    for(int i=1;i<=N;++i){
        std::fill(&dp[0][0], &dp[0][0] + 556 * 556, 0);
        dp[0][0] = 1;
        for(int j=1;j<=N;++j){
            dp[j][0] = dp[j-1][0] * i * (i - 1) % MOD;
            for(int k=1;k<=i;++k){
                dp[j][k] = (dp[j-1][k-1] + 1ll * (i * (i - 1) + k) % MOD * dp[j-1][k] % MOD) % MOD;
            }
        }

        c = (c + dp[N][i]) % MOD;
    }

    std::cout << c << std::endl;
}
0