結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー んんんんんん
提出日時 2022-12-22 22:28:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,992 bytes
コンパイル時間 3,329 ms
コンパイル使用メモリ 232,476 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-29 03:56:00
合計ジャッジ時間 13,872 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 70 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 619 ms
5,376 KB
testcase_09 AC 621 ms
5,376 KB
testcase_10 AC 611 ms
5,376 KB
testcase_11 AC 479 ms
5,376 KB
testcase_12 AC 580 ms
5,376 KB
testcase_13 AC 543 ms
5,376 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

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(2*N, vector<long long>(2*N, 0));
    for (int i = 0; i < 2*N; i++) {
        for (int j = 0; j < 2*N; j++) {
            for (int k = 0; k < 2*N; k++) {
                ret[i][j] += A[i][k] * B[k][j];
                ret[i][j] %= MOD;
            }
        }
    }

    return ret;
}

vector<vector<long long>> mulx(vector<vector<long long>> &A, const vector<vector<long long>> &B) {
    vector<vector<long long>> ret(2*N, vector<long long>(N, 0));
    for (int i = 0; i < 2*N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < 2*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>> edge(N, vector<long long>(N, 0));
    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        edge[s][t] = edge[t][s] = 1;
    }

    vector<vector<long long>> mat(2*N, vector<long long>(2*N, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            mat[i][j] = mat[i+N][j] = edge[i][j];
        }
        mat[i+N][i+N] = 1;
    }
    vector<vector<long long>> A(2*N, vector<long long>(2*N, 0));
    for (int i = 0; i < 2*N; i++) A[i][i] = 1;

    T--;
    while (T > 0) {
        if (T & 1) {
            A = mul(A, mat);
        }
        mat = mul(mat, mat);
        T /= 2;
    }
    vector<vector<long long>> B(2*N, vector<long long>(N, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            B[i][j] = edge[i][j];
        }
        B[i+N][i] = 1;
    }

    B = mulx(A, B);

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