結果

問題 No.572 妖精の演奏
ユーザー chocoruskchocorusk
提出日時 2018-12-11 23:08:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,421 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 98,164 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 16:05:58
合計ジャッジ時間 14,013 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,348 KB
testcase_01 AC 14 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 7 ms
4,348 KB
testcase_05 AC 56 ms
4,348 KB
testcase_06 AC 101 ms
4,348 KB
testcase_07 AC 29 ms
4,348 KB
testcase_08 AC 101 ms
4,348 KB
testcase_09 AC 150 ms
4,348 KB
testcase_10 AC 1,412 ms
4,348 KB
testcase_11 AC 1,421 ms
4,348 KB
testcase_12 AC 1,416 ms
4,348 KB
testcase_13 AC 1,407 ms
4,348 KB
testcase_14 AC 1,130 ms
4,348 KB
testcase_15 AC 1,419 ms
4,348 KB
testcase_16 AC 1,150 ms
4,348 KB
testcase_17 AC 1,410 ms
4,348 KB
testcase_18 AC 40 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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;
					if(n-1-x<0) continue;
					for(ll y=0; y<=m; y++){
						if(dp[k][k][y]==-1) continue;
						if(y==0){
							if(n-1-x>m) continue;
							ans=max(ans, (ll)dp[i][k][x]+(ll)dp[k][j][n-1-x]);
							continue;
						}
						for(ll z=(n-1-x)%y; z<=m; z+=y){
							if(dp[k][j][z]==-1) continue;
							if(n-1<x+z) 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