結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2024-09-27 17:12:15 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 716 bytes |
| コンパイル時間 | 3,239 ms |
| コンパイル使用メモリ | 252,260 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-27 17:12:20 |
| 合計ジャッジ時間 | 4,697 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}