結果

問題 No.572 妖精の演奏
ユーザー chocoruskchocorusk
提出日時 2018-12-11 23:02:02
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,499 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 98,000 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-24 14:07:31
合計ジャッジ時間 7,424 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
4,348 KB
testcase_01 AC 36 ms
4,348 KB
testcase_02 AC 6 ms
4,348 KB
testcase_03 AC 6 ms
4,348 KB
testcase_04 AC 14 ms
4,348 KB
testcase_05 AC 200 ms
4,348 KB
testcase_06 AC 414 ms
4,348 KB
testcase_07 AC 98 ms
4,348 KB
testcase_08 AC 406 ms
4,348 KB
testcase_09 AC 615 ms
4,348 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll n; int m;
	cin>>n>>m;
	int a[30][30];
	for(int i=0; i<m; i++){
		for(int j=0; j<m; j++){
			cin>>a[i][j];
		}
	}
	int dp[31][31][31];
	for(int i=0; i<m; i++){
		for(int j=0; j<m; j++){
			for(int k=0; k<=m; k++){
				dp[i][j][k]=-1;
			}
		}
	}
	for(int i=0; i<m; i++){
		dp[i][i][0]=0;
		for(int j=0; j<m; j++){
			for(int k=0; k<m; k++){
				if(dp[i][k][j]==-1) continue;
				for(int l=0; l<m; l++){
					dp[i][l][j+1]=max(dp[i][l][j+1], dp[i][k][j]+a[k][l]);
				}
			}
		}
	}
	ll ans=0;
	for(int i=0; i<m; i++){
		for(int j=0; j<m; j++){
			for(int k=0; k<m; k++){
				for(ll x=0; x<=m; x++){
					if(dp[i][k][x]==-1) continue;
					for(ll y=0; y<=m; y++){
						if(dp[k][k][y]==-1) continue;
						for(ll z=0; z<=m; z++){
							if(dp[k][j][z]==-1) continue;
							if(y==0 && n-1!=x+z) continue;
							if(y==0){
								ans=max(ans, (ll)dp[i][k][x]+(ll)dp[k][j][z]);
								continue;
							}
							if(n-1<x+z || (n-1-x-z)%y!=0) continue;
							ll c=(n-1-x-z)/y;
							ans=max(ans, (ll)dp[i][k][x]+(ll)dp[k][j][z]+c*(ll)dp[k][k][y]);
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
0