結果
| 問題 |
No.572 妖精の演奏
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-07 00:36:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,405 bytes |
| コンパイル時間 | 1,120 ms |
| コンパイル使用メモリ | 107,240 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 03:10:51 |
| 合計ジャッジ時間 | 1,726 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
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;
}