結果

問題 No.45 回転寿司
ユーザー abinull
提出日時 2025-08-24 14:46:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 402 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 74,220 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-24 14:46:59
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int main() {

int n;
cin >> n;

vector<int> v(n);
vector<int> s(n, 0);

for (int i=0;i<n;i++) cin >> v[i];

s[0] = v[0];
s[1] = max(v[0], v[1]);

for (int j=2;j<n;j++) {
    s[j] = max(s[j-2] + v[j], s[j-1]);
}

int res=0;

for (int i=0;i<n;i++) {
    res = max(res, s[i]);
}

cout << res << endl;

return 0;
}
0