結果
| 問題 |
No.2982 Logic Battle
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2024-12-07 02:27:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 259 ms / 2,000 ms |
| コード長 | 1,686 bytes |
| コンパイル時間 | 945 ms |
| コンパイル使用メモリ | 84,136 KB |
| 最終ジャッジ日時 | 2025-02-26 11:27:07 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 38 |
ソースコード
#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
using namespace std;
#include <atcoder/modint>
using Modint = atcoder::static_modint<998244353>;
void testcase(){
int N; cin >> N;
vector<vector<i64>> A(N);
rep(i,N){
A[i].resize(3);
rep(j,3) cin >> A[i][j];
}
vector<vector<i64>> dp(3, vector<i64>(N+1, -INF));
rep(x,3) dp[x][0] = 0;
i64 t_left = N;
for(auto& a : A){
vector<vector<i64>> nx(3, vector<i64>(N+1, -INF));
rep(i,3){
i64 b = a[i];
rep(x,N){
if(x+b >= N){
chmax(nx[i][N], dp[i][x] + (x+b) * t_left - (t_left * (t_left-1) / 2));
} else {
chmax(nx[i][x+b], dp[i][x]);
}
}
chmax(nx[i][N], dp[i][N] + b * t_left);
}
vector<vector<i64>> nx2(3, vector<i64>(N+1, -INF));
rep(t,3) rep(s,3) if(s != t){
chmax(nx2[t][0], nx[s][0]);
rep(i,N-1) chmax(nx2[t][i], nx[s][i+1] + (i+1));
chmax(nx2[t][N], nx[s][N]);
}
t_left--;
swap(dp, nx2);
}
i64 ans = -INF;
rep(j,3) rep(i,N+1) chmax(ans, dp[j][i]);
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
testcase();
return 0;
}
Nachia