結果

問題 No.572 妖精の演奏
ユーザー pekempeypekempey
提出日時 2017-10-06 22:31:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 954 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 77,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 17:17:12
合計ジャッジ時間 1,902 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using R = long long;
using Vector = std::vector<R>;
using Matrix = std::vector<Vector>;

Matrix mul(Matrix a, Matrix b) {
  const int n = a.size();
  Matrix c(n, Vector(n));
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      for (int j = 0; j < n; j++) {
        c[i][j] = max(c[i][j], a[i][k] + b[k][j]);
      }
    }
  }
  return c;
}

Matrix pow(Matrix a, long long b) {
  const int n = a.size();
  Matrix ret(n, Vector(n));
  for (int i = 0; i < n; i++) {
    ret[i][i] = 0;
  }
  for (; b > 0; b >>= 1) {
    if (b & 1) ret = mul(ret, a);
    a = mul(a, a);
  }
  return ret;
}

int main() {
  int n, m;
  cin >> n >> m;

  Matrix A(m, Vector(m));

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  A = pow(A, n - 1);

  cout << *max_element(begin(A[0]), end(A[0])) << endl;
}
0