結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー んんんんんん
提出日時 2022-12-22 22:40:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 2,936 ms
コンパイル使用メモリ 230,832 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 03:56:29
合計ジャッジ時間 7,577 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 63 ms
5,376 KB
testcase_09 AC 60 ms
5,376 KB
testcase_10 AC 62 ms
5,376 KB
testcase_11 AC 46 ms
5,376 KB
testcase_12 AC 65 ms
5,376 KB
testcase_13 AC 66 ms
5,376 KB
testcase_14 AC 329 ms
5,376 KB
testcase_15 AC 339 ms
5,376 KB
testcase_16 AC 326 ms
5,376 KB
testcase_17 AC 338 ms
5,376 KB
testcase_18 AC 365 ms
5,376 KB
testcase_19 AC 336 ms
5,376 KB
testcase_20 AC 227 ms
5,376 KB
testcase_21 AC 265 ms
5,376 KB
testcase_22 AC 47 ms
5,376 KB
testcase_23 AC 312 ms
5,376 KB
testcase_24 AC 35 ms
5,376 KB
testcase_25 AC 85 ms
5,376 KB
testcase_26 AC 28 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 43 ms
5,376 KB
testcase_31 AC 41 ms
5,376 KB
testcase_32 AC 41 ms
5,376 KB
testcase_33 AC 38 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

const int MOD = 998244353;

int N, M;
long long T;

vector<vector<long long>> mul(const vector<vector<long long>> &A, const vector<vector<long long>> &B) {
    vector<vector<long long>> ret(N, vector<long long>(N, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                ret[i][j] += A[i][k] * B[k][j];
                ret[i][j] %= MOD;
            }
        }
    }

    return ret;
}

int main() {
    cin >> N >> M >> T;
    vector<vector<long long>> mat(N, vector<long long>(N, 0));
    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        mat[s][t] = mat[t][s] = 1;
    }

    vector<vector<long long>> A(N, vector<long long>(N, 0));
    for (int i = 0; i < N; i++) A[i][i] = 1;

    while (T > 0) {
        if (T & 1) {
            A = mul(A, mat);
        }
        mat = mul(mat, mat);
        T >>= 1;
    }

    cout << A[0][0] << endl;
}
0