結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2024-09-27 14:15:49 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 559 bytes |
| コンパイル時間 | 3,170 ms |
| コンパイル使用メモリ | 247,288 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-27 14:15:53 |
| 合計ジャッジ時間 | 4,258 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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];
for (int i = 1; i < n; ++i) {
dp[i] = std::max(dp[i - 1], a[i]);
if (i - 2 >= 0) {
dp[i] = std::max(dp[i], dp[i - 2] + a[i]);
}
}
std::cout << dp[n - 1] << '\n';
return 0;
}