結果

問題 No.1112 冥界の音楽
ユーザー SSRSSSRS
提出日時 2020-07-10 21:52:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,776 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 172,784 KB
実行使用メモリ 11,676 KB
最終ジャッジ日時 2024-04-19 16:51:06
合計ジャッジ時間 18,181 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 380 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 38 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 92 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 TLE -
testcase_15 AC 362 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 467 ms
5,376 KB
testcase_18 AC 466 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 61 ms
5,376 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 325 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 19 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1,544 ms
6,944 KB
testcase_31 AC 18 ms
5,376 KB
testcase_32 AC 1,665 ms
6,940 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
vector<vector<long long>> matrix_multiplication(vector<vector<long long>> &A, vector<vector<long long>> &B){
  int N = A.size();
  int M = B.size();
  int K = B[0].size();
  vector<vector<long long>> ans(N, vector<long long>(K, 0));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      for (int k = 0; k < K; k++){
        ans[i][k] += A[i][j] * B[j][k];
        ans[i][k] %= MOD;
      }
    }
  }
  return ans;
}
vector<vector<long long>> matrix_exponentiation(vector<vector<long long>> A, long long b){
  int N = A.size();
  vector<vector<long long>> ans(N, vector<long long>(N, 0));
  for (int i = 0; i < N; i++){
    ans[i][i] = 1;
  }
  while (b > 0){
    if (b % 2 == 1){
      ans = matrix_multiplication(ans, A);
    }
    A = matrix_multiplication(A, A);
    b /= 2;
  }
  return ans;
}
int main(){
  int K, M;
  long long N;
  cin >> K >> M >> N;
  vector<int> P(M), Q(M), R(M);
  for (int i = 0; i < M; i++){
    cin >> P[i] >> Q[i] >> R[i];
    P[i]--;
    Q[i]--;
    R[i]--;
  }
  vector<vector<long long>> mat(K * K * K, vector<long long>(K * K * K, 0));
  for (int i = 0; i < M; i++){
    for (int j = 0; j < M; j++){
      if (Q[i] == P[j] && R[i] == Q[j]){
        mat[P[j] + Q[j] * K + R[j] * K * K][P[i] + Q[i] * K + R[i] * K * K] = 1;
      }
    }
  }
  N -= 3;
  mat = matrix_exponentiation(mat, N);
  vector<long long> vec(K * K * K, 0);
  for (int i = 0; i < M; i++){
    if (P[i] == 0){
      vec[P[i] + Q[i] * K + R[i] * K * K] = 1;
    }
  }
  long long ans = 0;
  for (int i = 0; i < K * K * K; i++){
    for (int j = 0; j < K * K * K; j++){
      if (i < K * K){
        ans += mat[i][j] * vec[j];
      }
    }
  }
  ans %= MOD;
  cout << ans << endl;
}
0