結果

問題 No.1749 ラムドスウイルスの感染拡大
ユーザー 👑 箱星箱星
提出日時 2021-10-14 20:51:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,734 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 81,100 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 06:24:17
合計ジャッジ時間 2,417 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

const long long mod=998244353;

vector<vector<long long>> matrix_mul(const vector<vector<long long>>& A,const vector<vector<long long>>&B){
  vector<vector<long long>>C(A.size(),vector<long long>(B.at(0).size(),0));
  for(int i=0;i<A.size();i++){
    for(int k=0;k<B.size();k++){
      for(int j=0;j<B.at(0).size();j++){
        C.at(i).at(j)=(C.at(i).at(j)+A.at(i).at(k)*B.at(k).at(j))%mod;
      }
    }
  }
  return C;
}

vector<vector<long long>> matrix_exp(vector<vector<long long>> X,long long n){
  vector<vector<long long>>Y(X.size(),vector<long long>(X.size(),0));
  for(int i=0;i<X.size();i++){
    Y.at(i).at(i)=1;
  }
  while(n>0){
    if(n&1){
      Y=matrix_mul(Y,X);
    }
    X=matrix_mul(X,X);
    n>>=1;
  }
  return Y;
}

long long calculate_nth(long long n,vector<vector<long long>> A, vector<vector<long long>> b){
  A=matrix_exp(A,n);
  vector<vector<long long>> res;
  res=matrix_mul(A,b);
  return res.at(0).at(0);
}

long long mod_pow(long long x,long long n,long long m){
  long long res=1;
  while(n>0){
    if(n&1){
      res=res*x%m;
    }
    x=x*x%m;
    n>>=1;
  }
  return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, t;
    cin >> n >> m >> t;
    if (n > 200) return 0;
    vector<vector<long long>> a(n, vector<long long>(n, 0));
    vector<vector<long long>> b(n, vector<long long>(n, 0));
    b[0][0] = 1;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        a[u][v] = 1;
        a[v][u] = 1;
    }
    long long ans;
    ans=calculate_nth(t,a,b);
    cout<<ans<<endl;
}
0