結果
| 問題 | No.45 回転寿司 |
| ユーザー |
|
| 提出日時 | 2024-09-27 17:12:15 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 5,000 ms |
| + 466µs | |
| コード長 | 716 bytes |
| 記録 | |
| コンパイル時間 | 2,431 ms |
| コンパイル使用メモリ | 336,088 KB |
| 実行使用メモリ | 9,764 KB |
| 最終ジャッジ日時 | 2026-09-05 07:34:40 |
| 合計ジャッジ時間 | 4,209 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n;
std::cin >> n;
std::vector<i64> a(n);
for (auto &x : a) std::cin >> x;
constexpr i64 inf = std::numeric_limits<i64>::max() >> 4;
std::vector<i64> dp(n, -inf);
dp[0] = a[0];
i64 max = -inf;
for (int i = 1; i < n; ++i) {
dp[i] = a[i];
if (i - 2 >= 0) {
max = std::max(max, dp[i - 2]);
dp[i] = std::max(dp[i], dp[i] + max);
}
}
// for (int i = 0; i < n; ++i) {
// std::cout << dp[i] << " ";
// }
// std::cout << '\n';
std::cout << std::ranges::max(dp) << '\n';
return 0;
}