結果

問題 No.572 妖精の演奏
ユーザー ryoissyryoissy
提出日時 2017-10-06 22:42:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,036 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 159,512 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 10:43:13
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 3 ms
6,948 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 WA -
testcase_19 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]);
      |                         ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#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[31][31][31];
ll dp2[31][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;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;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%i;
		ll maxi=0;
		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);
		}
	}
	printf("%lld\n",res);
	return 0;
}
0