結果

問題 No.572 妖精の演奏
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-10-07 00:59:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,840 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 168,020 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 18:27:22
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




typedef long long ll;
ll N; int M;
ll A[30][30];
ll dp[40][30][30];
ll ans[30][30];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(y, 0, M) rep(x, 0, M) cin >> A[y][x];

    rep(y, 0, M) rep(x, 0, M) dp[0][y][x] = A[y][x];
    rep(d, 1, 40) rep(x, 0, M) rep(y, 0, M) {
        rep(z, 0, M) dp[d][x][y] = max(dp[d][x][y], dp[d - 1][x][z] + dp[d - 1][z][y]);
    }
    N--;
    int d = 0;
    while (N) {
        if (N % 2) {
            ll ans2[30][30];
            rep(x, 0, M) rep(y, 0, M) ans2[x][y] = 0;

            rep(x, 0, M) rep(y, 0, M) {
                rep(z, 0, M) ans2[x][y] = max(ans2[x][y], ans[x][z] + dp[d][z][y]);
            }

            swap(ans, ans2);
        }

        N /= 2;
        d++;
    }

    ll a = 0;
    rep(x, 0, M) rep(y, 0, M) a = max(a, ans[x][y]);
    cout << a << endl;
}
0