結果

問題 No.572 妖精の演奏
ユーザー mamekinmamekin
提出日時 2017-10-07 00:36:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,405 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 108,240 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 18:26:37
合計ジャッジ時間 1,806 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    long long n;
    int m;
    cin >> n >> m;
    vector<vector<long long> > v(m, vector<long long>(m));
    for(int i=0; i<m; ++i){
        for(int j=0; j<m; ++j){
            cin >> v[i][j];
        }
    }

    vector<long long> ans(m, 0);
    -- n;
    while(n > 0){
        if(n & 1){
            vector<long long> ans2(m, 0);
            for(int a=0; a<m; ++a){
                for(int b=0; b<m; ++b){
                    ans2[b] = max(ans2[b], ans[a] + v[a][b]);
                }
            }
            ans.swap(ans2);
        }
        n >>= 1;

        vector<vector<long long> > v2(m, vector<long long>(m, 0));
        for(int a=0; a<m; ++a){
            for(int b=0; b<m; ++b){
                for(int c=0; c<m; ++c){
                    v2[a][c] = max(v2[a][c], v[a][b] + v[b][c]);
                }
            }
        }
        v.swap(v2);
    }
    cout << *max_element(ans.begin(), ans.end()) << endl;

    return 0;
}
0