結果

問題 No.45 回転寿司
ユーザー mine691
提出日時 2018-08-13 17:49:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 65,536 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 19:15:28
合計ジャッジ時間 1,672 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;

int main() {
	int n, v[1010] = { 0 };
	cin >> n;
	cin >> v[1];
	if (n == 1) {
		cout << v[1] << endl;
		return 0;
	}
	cin >> v[2];
	if (n == 2) {
		cout << max(v[1], v[2]) << endl;
		return 0;
	}
	else {
		cin >> v[3];
		v[3] += v[1];
		if (n == 3) {
			cout << max(v[3], v[2]) << endl;
			return 0;
		}
		for (int i = 4;i <= n;i++) {
			int vv;
			cin >> vv;
			v[i] = max(v[i - 2], v[i - 3]) + vv;
		}
		cout << max(v[n], v[n - 1]) << endl;
	}
}
0