結果

問題 No.572 妖精の演奏
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-07-08 09:51:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,585 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 60,816 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 01:18:34
合計ジャッジ時間 1,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 16 ms
4,376 KB
testcase_11 AC 23 ms
4,376 KB
testcase_12 AC 27 ms
4,376 KB
testcase_13 AC 35 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>

const int LIMIT=100;


int main(){
	long long int as[LIMIT][LIMIT],dp[LIMIT][LIMIT],nextdp[LIMIT][LIMIT],ansdp[LIMIT][LIMIT];
	int n,m;
	scanf("%d",&n);
	scanf("%d",&m);
	bool last1=(n%2==1);
	n/=2;
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			std::cin>>as[i][j];
			dp[i][j]=as[i][j];
		}
	}
	memset(ansdp,0,sizeof(ansdp));
	bool first=true;
	while(n>0){
		memset(nextdp,0,sizeof(nextdp));
		if(n%2==1){
			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++){
							
							long long int t;	
							if(first==true){
								t=dp[i][l];
								
							}else{
								t=dp[i][j]+as[j][k]+ansdp[k][l];
							}
							nextdp[i][l]=std::max(nextdp[i][l],t);
						}
					}
				}
			}
			first=false;
			memcpy(ansdp,nextdp,sizeof(nextdp));
		}
		
		memset(nextdp,0,sizeof(nextdp));
		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++){
						long long int t=dp[i][j]+as[j][k]+dp[k][l];
						nextdp[i][l]=std::max(t,nextdp[i][l]);
					}
				}
			}
		}
		memcpy(dp,nextdp,sizeof(nextdp));
		n/=2;
	}
	if(last1==true){
		memset(nextdp,0,sizeof(nextdp));
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					long long int t=as[i][j]+ansdp[j][k];
					nextdp[i][k]=std::max(t,nextdp[i][k]);
				}
			}
		}
		memcpy(ansdp,nextdp,sizeof(nextdp));
	}
	long long int ans=0;
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			ans=std::max(ans,ansdp[i][j]);
		}
	}
	std::cout<<ans<<"\n";
}
0