結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2017-06-24 00:31:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 621 bytes |
| コンパイル時間 | 1,353 ms |
| コンパイル使用メモリ | 67,208 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-27 16:28:19 |
| 合計ジャッジ時間 | 2,697 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <algorithm>
#define rep(i, n) for(int (i)=0; (i)<(n); ++(i))
using namespace std;
int main()
{
int n;
cin >> n;
int val[1001];
int ans[1001][2];
rep(i,n) {
cin >> val[i];
}
ans[0][0] = 0;
ans[0][1] = val[0];
ans[1][0] = val[0];
ans[1][1] = val[1];
for(int i=2; i<n; ++i) {
ans[i][0] = max(ans[i-1][1], ans[i-2][1]);
ans[i][1] = max(ans[i-1][0], ans[i-2][0]) + val[i];
}
cout << max(ans[n-1][0], ans[n-1][1]) << endl;
return 0;
}