結果

問題 No.1112 冥界の音楽
ユーザー SSRSSSRS
提出日時 2020-07-10 21:50:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,758 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 173,232 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 16:47:14
合計ジャッジ時間 13,713 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 381 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 39 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 94 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 TLE -
testcase_15 AC 366 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 473 ms
6,944 KB
testcase_18 AC 475 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 65 ms
6,940 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 328 ms
6,944 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

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, int 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, 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