結果
問題 |
No.572 妖精の演奏
|
ユーザー |
![]() |
提出日時 | 2018-07-22 11:23:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,574 bytes |
コンパイル時間 | 817 ms |
コンパイル使用メモリ | 80,796 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-26 05:08:43 |
合計ジャッジ時間 | 1,739 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 20 |
ソースコード
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<stack> #include<queue> #include<vector> #include<algorithm> #include<string> #include<iostream> #include<set> #include<map> #include<bitset> using namespace std; typedef long long ll; #define i_7 1000000007 #define i_5 1000000005 ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; else return c+i_7; } typedef pair<int,int> i_i; typedef pair<ll,ll> l_l; ll inf=1000000000000;/*10^12*/ #define rep(i,l,r) for(ll i=l;i<=r;i++) ll max(ll a,ll b){if(a<b)return b;else return a;} ll min(ll a,ll b){if(a>b)return b;else return a;} ////////////////////////////////////// int main(){ int n,m;cin>>n>>m; int a[m][m];rep(i,0,m-1)rep(j,0,m-1)cin>>a[i][j]; ll dp[m][m][35];memset(dp,0,sizeof(dp)); rep(i,0,m-1)rep(j,0,m-1){ dp[i][j][0]=a[i][j]; } rep(k,1,34){ rep(s,0,m-1){ rep(t,0,m-1){ rep(i,0,m-1){ dp[s][t][k]=max(dp[s][t][k],dp[s][i][k-1]+dp[i][t][k-1]); } } } } /* rep(s,0,m-1){ rep(t,0,m-1){ cout<<dp[s][t][2]<<" "; } cout<<endl; }*/ ll x[35];memset(x,0,sizeof(x)); rep(i,0,34){ rep(s,0,m-1){ rep(t,0,m-1){ x[i]=max(x[i],dp[s][t][i]); } } } /* rep(i,0,3){ cout<<x[i]<<" "; }*/ ll ans=0; int stop=(int)log2(n); rep(i,0,stop+1){ if(((n>>i)&1)==1)ans+=x[i]; } cout<<ans<<endl; return 0; }