結果

問題 No.572 妖精の演奏
ユーザー KKT89KKT89
提出日時 2023-07-09 19:53:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,903 bytes
コンパイル時間 2,949 ms
コンパイル使用メモリ 217,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 23:41:13
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int m; cin >> m;
    vector<vector<vector<ll>>> d(35, vector<vector<ll>>(m, vector<ll>(m)));
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> d[1][i][j];
        }
    }
    for (int i = 2; i < 35; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k < m; ++k) {
                for (int l = 0; l < m; ++l) {
                    for (int p = 0; p < m; ++p) {
                        d[i][j][p] = max(d[i][j][p], d[i-1][j][k] + d[1][k][l] + d[i-1][l][p]);
                    }
                }
            }
        }
    }
    vector<vector<ll>> res(m, vector<ll>(m));
    bool f = false;
    for (int i = 0; i < 35; ++i) {
        if (!((1LL<<i)&n)) continue;
        vector<vector<ll>> nres(m, vector<ll>(m));
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k < m; ++k) {
                for (int l = 0; l < m; ++l) {
                    for (int p = 0; p < m; ++p) {
                        if(f) nres[j][p] = max(nres[j][p], res[j][k] + d[1][k][l] + d[i][l][p]);
                        else nres[j][p] = d[i][j][p];
                    }
                }
            }
        }
        f = true;
        swap(res, nres);
    }
    ll mx = 0;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            mx = max(mx, res[i][j]);
        }
    }
    cout << mx << endl;
}
0