結果

問題 No.572 妖精の演奏
ユーザー mamekinmamekin
提出日時 2017-10-06 23:03:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,592 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 107,920 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 17:22:51
合計ジャッジ時間 2,100 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 21 ms
4,376 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 21 ms
4,380 KB
testcase_17 AC 22 ms
4,376 KB
testcase_18 AC 2 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;

const int INF = INT_MAX / 2;

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

    vector<vector<vector<int> > > dp(m+1, vector<vector<int> >(m, vector<int>(m, -INF)));
    for(int i=0; i<m; ++i)
        dp[0][i][i] = 0;
    for(int t=0; t<m; ++t){
        for(int a=0; a<m; ++a){
            for(int b=0; b<m; ++b){
                for(int c=0; c<m; ++c){
                    dp[t+1][a][c] = max(dp[t+1][a][c], dp[t][a][b] + v[b][c]);
                }
            }
        }
    }

    long long ans = 0;
    for(int s=0; s<min<long long>(n,m); ++s){
        for(int t=1; t<=m; ++t){
            for(int a=0; a<m; ++a){
                for(int b=0; b<m; ++b){
                    for(int c=0; c<m; ++c){
                        long long tmp = dp[s][a][b] + dp[t][b][b] * ((n - 1 - s) / t) + dp[(n - 1 - s) % t][b][c];
                        ans = max(ans, tmp);
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0