結果

問題 No.2435 Order All Company
ユーザー yuyu_5510yuyu_5510
提出日時 2023-08-11 19:52:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,061 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 207,468 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-15 15:10:38
合計ジャッジ時間 4,234 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
const long long mod = 998244353;

int main(){
    int N, K;
    cin >> N >> K;
    vector G(K, vector(N, vector(N, 0LL)));
    for(int i = 0;i < K;i++){
        int t;
        cin >> t;
        for(int j = 0;j < t;j++){
            int a, b;
            cin >> a >> b;
            --a;--b;
            G[i][a][b] += 1;
            G[i][b][a] += 1;
        }
    }

    vector<vector<long long>> dp(N+1, vector<long long>(1<<K, 0));
    dp[1][0] = 1;


    for(int i = 1;i < N;i++){
        //各iについて、iとi以下をつなぐものを事前計算
        vector<long long> cnt(K);
        for(int j = 0;j < K;j++){
            for(int k = 0;k < i;k++){
                cnt[j] += G[j][k][i];
                cnt[j] %= mod;
            }
        }
        
        for(int j = 0;j < 1<<K;j++){
            for(int k = 0;k < K;k++){
                dp[i+1][j | 1<<k] += (cnt[k] * dp[i][j]) % mod;
                dp[i+1][j | 1<<k] %= mod;
            }
        }
    }

    cout << dp[N][(1<<K)-1] << endl;

}
0