結果

問題 No.1112 冥界の音楽
ユーザー tnakao0123tnakao0123
提出日時 2020-07-12 03:03:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,142 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 94,728 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 21:09:32
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 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 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 4 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 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 9 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 9 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 25 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1112.cc:  No.1112 冥界の音楽 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_K = 6;
const int MAX_KK = MAX_K * MAX_K;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;
typedef int vec[MAX_KK];
typedef vec mat[MAX_KK];

/* global variables */

mat ma, mb;
vec va, vb;

/* subroutines */

inline void initmat(const int n, mat a) { memset(a, 0, sizeof(mat)); }
inline void unitmat(const int n, mat a) {
  initmat(n, a);
  for (int i = 0; i < n; i++) a[i][i] = 1;
}

inline void copymat(const int n, const mat a, mat b) {
  memcpy(b, a, sizeof(mat));
}

inline void mulmat(const int n, const mat a, const mat b, mat c) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      c[i][j] = 0;
      for (int k = 0; k < n; k++)
        c[i][j] = (c[i][j] + (ll)a[i][k] * b[k][j] % MOD) % MOD;
    }
}

inline void powmat(const int n, const mat a, ll b, mat c) {
  mat s, t;
  copymat(n, a, s);
  unitmat(n, c);

  while (b > 0) {
    if (b & 1) {
      mulmat(n, c, s, t);
      copymat(n, t, c);
    }

    mulmat(n, s, s, t);
    copymat(n, t, s);
    b >>= 1;
  }
}

inline void mulmatvec(const int n, const mat a, const vec b, vec c) {
  for (int i = 0; i < n; i++) {
    c[i] = 0;
    for (int j = 0; j < n; j++)
      c[i] = (c[i] + (ll)a[i][j] * b[j] % MOD) % MOD;
  }
}

/* main */

int main() {
  int k, m;
  ll n;
  scanf("%d%d%lld", &k, &m, &n);
  int kk = k * k;

  for (int i = 0; i < m; i++) {
    int p, q, r;
    scanf("%d%d%d", &p, &q, &r);
    p--, q--, r--;

    int u = p * k + q, v = q * k + r;
    ma[v][u] = 1;
  }

  powmat(kk, ma, n - 2, mb);
  for (int i = 0; i < k; i++) va[i] = 1;
  mulmatvec(kk, mb, va, vb);

  int sum = 0;
  for (int i = 0; i < k; i++) sum = (sum + vb[i * k]) % MOD;

  printf("%d\n", sum);
  return 0;
}
0