結果
問題 | No.2982 Logic Battle |
ユーザー |
![]() |
提出日時 | 2024-12-07 00:08:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 583 ms / 2,000 ms |
コード長 | 1,193 bytes |
コンパイル時間 | 4,585 ms |
コンパイル使用メモリ | 254,888 KB |
最終ジャッジ日時 | 2025-02-26 11:19:04 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 38 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000000LL long long a[5005][3]; int main(){ int n; cin>>n; rep(i,n){ rep(j,3)cin>>a[i][j]; } vector dp(n+5,vector<long long>(3,-Inf64)); rep(i,3)dp[0][i] = 0; vector ndp(n+5,vector<long long>(3,-Inf64)); rep(i,n){ { ndp.assign(n+5,vector<long long>(3,-Inf64)); rep(j,n+5){ rep(k,3){ if(dp[j][k] == -Inf64)continue; rep(l,3){ if(k == l)continue; long long nj = j + a[i][l]; long long nv = dp[j][k]; if(nj>=n+5){ nv += ((long long)nj-(n+4)) * (n-i); nj = n+4; } ndp[nj][l] = max(ndp[nj][l],nv); } } } swap(dp,ndp); } { ndp.assign(n+5,vector<long long>(3,-Inf64)); rep(j,n+5){ rep(k,3){ if(dp[j][k] == -Inf64)continue; ndp[max(j-1,0)][k] = max(ndp[max(j-1,0)][k],dp[j][k] + j); } } swap(dp,ndp); } } long long ans = -Inf64; rep(i,n+5){ rep(j,3){ ans = max(ans,dp[i][j]); } } cout<<ans<<endl; return 0; }