結果
問題 | No.572 妖精の演奏 |
ユーザー |
|
提出日時 | 2017-10-06 23:03:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,592 bytes |
コンパイル時間 | 1,141 ms |
コンパイル使用メモリ | 109,160 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 01:54:09 |
合計ジャッジ時間 | 2,012 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#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;}