結果

問題 No.2435 Order All Company
ユーザー yuyu_5510yuyu_5510
提出日時 2023-08-11 20:49:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,247 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 204,820 KB
実行使用メモリ 12,940 KB
最終ジャッジ日時 2023-08-15 15:10:44
合計ジャッジ時間 3,973 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,452 KB
testcase_01 AC 4 ms
11,712 KB
testcase_02 AC 4 ms
11,432 KB
testcase_03 WA -
testcase_04 AC 4 ms
11,432 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 4 ms
11,432 KB
testcase_13 AC 4 ms
11,508 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(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    
    long long N,K;
    cin >> N >> K;
    vector<vector<pair<long long,long long>>> E(K);
    for(int k=0;k<K;k++){
        long long t;
        cin >> t;
        E[k].resize(t);
        for(int i=0;i<t;i++){
            long long a,b;
            cin >> a >> b;
            a--;b--;
            if(a>b)swap(a,b);
            E[k][i] = {a,b};
        }
    } 

    //B[i][j] := k-iの橋をj社に発注できるようなk(<i)の数
    long long B[1000][10]={};
    for(int j=0;j<K;j++){
        for(int i=0;i<(int)E[j].size();i++){
            B[E[j][i].second][j]++;
        }
    } 

    //dp[i][S] := 0番~i番までの街が連結になり、発注した建設会社の集合がSのときの発注の仕方の数
    long long dp[1001][1024] = {};
    dp[0][0] = 1;

    for(int i=0;i<N-1;i++){
        for(int S=0;S<(1<<K);S++){
            for(int j=0;j<K;j++){
                dp[i+1][S|(1<<j)] += (B[i+1][j]*dp[i][S])%MOD;
                dp[i+1][S|(1<<j)] %= MOD;
            }
        }
    }

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

    return 0;
}
0