結果
| 問題 |
No.572 妖精の演奏
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2017-10-09 20:25:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,078 bytes |
| コンパイル時間 | 1,649 ms |
| コンパイル使用メモリ | 168,068 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 07:02:27 |
| 合計ジャッジ時間 | 2,807 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = long long;
using P = std::tuple<int,int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
ll N, M;
int A[50][50];
ll dp[40][50][50], _dp[50][50], __dp[50][50];
// merge dp1 and dp2 -> dp3
void merge(const ll (&dp1)[50][50], const ll (&dp2)[50][50], ll (&dp3)[50][50]){
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
dp3[i][j] = -1001001001001001001ll;
}
}
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
for(int k=0;k<M;++k){
for(int l=0;l<M;++l){
dp3[i][j] = max(dp3[i][j], dp1[i][k] + A[k][l] + dp2[l][j]);
}
}
}
}
}
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N >> M;
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
std::cin >> A[i][j];
}
}
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
if(i == j){continue;}
_dp[i][j] = -1001001001001001001ll;
dp[0][i][j] = -1001001001001001001ll;
}
}
for(int i=1;i<40;++i){
merge(dp[i-1], dp[i-1], dp[i]);
if(N >> i & 1){
merge(dp[i], _dp, __dp);
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
_dp[i][j] = __dp[i][j];
}
}
// std::cout << i << std::endl;
// for(int i=0;i<M;++i){
// for(int j=0;j<M;++j){
// std::cout << _dp[i][j] << " \n"[j + 1 == M];
// }
// }
// std::cout << "----------" << std::endl;
}
}
ll res = 0ll;
for(int i=0;i<M;++i){
for(int j=0;j<M;++j){
res = max(res, _dp[i][j]);
}
}
std::cout << res << std::endl;
}
tottoripaper