結果

問題 No.1112 冥界の音楽
ユーザー SSRSSSRS
提出日時 2020-07-10 21:52:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,606 ms / 2,000 ms
コード長 1,746 bytes
コンパイル時間 2,044 ms
コンパイル使用メモリ 172,412 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 16:52:13
合計ジャッジ時間 6,448 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 67 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 8 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 409 ms
5,376 KB
testcase_15 AC 66 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 84 ms
5,376 KB
testcase_18 AC 84 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 385 ms
5,376 KB
testcase_22 AC 374 ms
5,376 KB
testcase_23 AC 59 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 266 ms
5,376 KB
testcase_31 AC 5 ms
5,376 KB
testcase_32 AC 301 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1,606 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const 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; i++){
    for (int j = 0; j < K * K * K; j++){
      ans += mat[i][j] * vec[j];
    }
  }
  ans %= MOD;
  cout << ans << endl;
}
0