結果
| 問題 | No.572 妖精の演奏 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-10-06 23:06:48 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 1,136 bytes | 
| コンパイル時間 | 1,309 ms | 
| コンパイル使用メモリ | 159,460 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-17 01:54:29 | 
| 合計ジャッジ時間 | 2,018 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:33: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll*’ {aka ‘long long int*’} [-Wformat=]
   17 |                         scanf("%d",&a[i][j]);
      |                                ~^  ~~~~~~~~
      |                                 |  |
      |                                 |  ll* {aka long long int*}
      |                                 int*
      |                                %lld
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%lld%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:17:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                         scanf("%d",&a[i][j]);
      |                         ~~~~~^~~~~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n;
int m;
ll a[31][31];
ll dp[61][31][31];
ll dp2[61][31];
int main(void){
	scanf("%lld%d",&n,&m);
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<m;i++){
		dp[0][i][i]=0;
	}
	for(int i=0;i<m*2;i++){
		for(int j=0;j<m;j++){
			for(int l=0;l<m;l++){
				if(dp[i][j][l]==-1)continue;
				for(int k=0;k<m;k++){
					dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][l]+a[l][k]);
				}
			}
		}
	}
	for(int i=1;i<m*2;i++){
		for(int j=0;j<m;j++){
			for(int k=0;k<m;k++){
				dp2[i+1][k]=max(dp2[i+1][k],dp2[i][j]+a[j][k]);
			}
		}
	}
	ll res=0;
	for(ll i=2;i<=m;i++){
		ll lot=n-1LL;
		ll rest=n-(lot/i)*i;
		for(int k=0;k<m;k++){
			ll now=(ll)dp[i][k][k]*(lot/i);
			for(int l=1;l<=rest;l++){
				for(int ab=0;ab<m;ab++){
					res=max(res,now+dp2[l][k]+dp[rest-l][k][ab]);
				}
			}
			res=max(res,now);
		}
	}
	if(n<=60){
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				res=max(res,dp2[n][j]);
			}
		}
	}
	printf("%lld\n",res);
	return 0;
}
            
            
            
        