結果

問題 No.572 妖精の演奏
ユーザー yuliicppyyuliicppy
提出日時 2020-05-03 20:43:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,511 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 97,560 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-22 23:32:18
合計ジャッジ時間 1,830 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;
#define DEBUG_ //!!·$BDs=P;~$K%3%a%s%H%"%&%H·(B!!
#ifdef DEBUG_
#define dump(x) cerr << #x << " = " << (x) << endl;
#else
#define dump(x) ;
#endif
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
//#define int long long
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <typename T>
std::string printVector(const std::vector<T> &data)
{
std::stringstream ss;
std::ostream_iterator<T> out_it(ss, ", ");
ss << "[";
std::copy(data.begin(), data.end() - 1, out_it);
ss << data.back() << "]";
return ss.str();
}
template <typename T>
void print_array(const T &ary, int size){
REP(i,size){
cout << ary[i] << " ";
}
cout << endl;
}
const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
LL A[30][30];
LL dp[40][30][30];
LL ans[30][30];
// https://www.hamayanhamayan.com/entry/2017/10/07/010528
signed main(int argc, char const *argv[])
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(12);
LL N,M; cin >> N >> M;
REP(i,M) REP(j,M) cin >> A[i][j];
REP(i,M) REP(j,M) dp[0][i][j] = A[i][j];
FOR(i,1,40) REP(x,M) REP(y,M){
REP(z,M){
dp[i][x][y] = max(dp[i][x][y], dp[i-1][x][z] + dp[i-1][z][y]);
}
}
N--;
int d = 0;
while(N){
if(N%2){
LL ans2[30][30];
REP(x,M) REP(y,M) ans2[x][y] = 0;
REP(x,M) REP(y,M){
REP(z,M) ans2[x][y] = max(ans2[x][y], ans[x][z] + dp[d][z][y]);
}
swap(ans,ans2);
}
N /= 2;
d++;
}
LL a = 0;
REP(x,M) REP(y,M) chmax(a,ans[x][y]);
cout << a << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0