結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー |
|
提出日時 | 2021-01-29 21:31:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 998 bytes |
コンパイル時間 | 719 ms |
コンパイル使用メモリ | 75,400 KB |
最終ジャッジ日時 | 2025-01-18 08:54:33 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
#line 1 "main.cpp" #include <iostream> #include <vector> using namespace std; using lint = long long; bool judge(int a, int b, int c) { if (a == c) return false; return (a < b && b > c) || (a > b && b < c); } constexpr lint INF = 1LL << 50; void solve() { int n; cin >> n; vector<int> xs(n); for (auto& x : xs) cin >> x; lint ans = -INF; for (int q = 0; q < 3; ++q) { vector<lint> dp(n + 1, -INF); dp[0] = 0; for (int i = 0; i < n; ++i) { dp[i + 1] = max(dp[i + 1], dp[i]); if (i + 2 < n && judge(xs[i], xs[i + 1], xs[i + 2])) { dp[i + 3] = max(dp[i + 3], dp[i] + xs[i]); } } ans = max(ans, dp.back()); xs.insert(xs.begin(), xs.back()); xs.pop_back(); } cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while (q--) solve(); return 0; }