結果

問題 No.2982 Logic Battle
ユーザー umezo
提出日時 2024-12-07 00:46:41
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 851 bytes
コンパイル時間 2,663 ms
コンパイル使用メモリ 245,820 KB
実行使用メモリ 601,384 KB
最終ジャッジ日時 2024-12-07 00:47:11
合計ジャッジ時間 17,658 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other MLE * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;

ll A[5050][3];
ll dp[5050][5050][3];
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  rep(i,5050) rep(j,5050) rep(k,3) dp[i][j][k]=-1;
  
  int n;
  cin>>n;
  rep(i,n) rep(j,3) cin>>A[i][j];
  
  rep(j,3) dp[0][max(0,min(5000,(int)A[0][j]-1))][j]=A[0][j];
  for(int i=0;i<n-1;i++) rep(j,5001) rep(k,3) rep(l,3){
    if(k==l) continue;
    if(dp[i][j][k]==-1) continue;
    dp[i+1][max(0,min(5000,j+(int)A[i+1][l]-1))][l]=max(dp[i+1][max(0,min(5000,j+(int)A[i+1][l]-1))][l],dp[i][j][k]+j+A[i+1][l]);
  }
  ll ans=0;
  rep(j,5001) rep(k,3) ans=max(ans,dp[n-1][j][k]);
  cout<<ans<<endl;
    
  return 0;
}
0