結果

問題 No.572 妖精の演奏
ユーザー kotatsugamekotatsugame
提出日時 2017-10-09 06:16:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 69,280 KB
実行使用メモリ 4,652 KB
最終ジャッジ日時 2023-08-10 20:45:46
合計ジャッジ時間 1,606 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 4 ms
4,420 KB
testcase_12 AC 4 ms
4,432 KB
testcase_13 AC 4 ms
4,388 KB
testcase_14 AC 3 ms
4,516 KB
testcase_15 AC 4 ms
4,388 KB
testcase_16 AC 4 ms
4,508 KB
testcase_17 AC 3 ms
4,652 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    5 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
long A[40][40][40],B[40][40][40],n,m,ans;
main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)for(int j=0;j<m;j++)cin>>A[0][i][j];
	for(int i=0;i<39;i++)for(int x=0;x<m;x++)for(int y=0;y<m;y++)for(int z=0;z<m;z++)A[i+1][x][y]=max(A[i+1][x][y],A[i][x][z]+A[i][z][y]);
	n--;
	for(int i=0;i<39;i++)
	{
		if(n&(1L<<i))
		{
			for(int x=0;x<m;x++)for(int y=0;y<m;y++)
			{
				for(int z=0;z<m;z++)B[i+1][x][y]=max(B[i+1][x][y],B[i][x][z]+A[i][z][y]);
				ans=max(ans,B[i+1][x][y]);
			}
		}
		else
		{
			for(int x=0;x<m;x++)for(int y=0;y<m;y++)B[i+1][x][y]=B[i][x][y];
		}
	}
	cout<<ans<<endl;
}
0