結果

問題 No.45 回転寿司
ユーザー 09SEPGR09SEPGR
提出日時 2017-10-21 23:31:03
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,789 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 79,000 KB
実行使用メモリ 814,592 KB
最終ジャッジ日時 2024-05-01 09:21:07
合計ジャッジ時間 4,504 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * main.cpp
 *
 *  Created on: 2017/10/06
 *      Author: sep
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

inline int main003();
inline int main045();
inline int main3();
inline int main4();

#define TEST

int main() {

#ifdef TEST
	while (1)
#endif
		main045();

	return 0;
}

inline int get_bit(int x) {

	int c = 0;

	while (x) {
		if (x & 1)
			c++;
		x >>= 1;
	}
	return c;
}

inline int main003() {

	int num;
	int route, v1, v2, bit_count;
	int result = 0;
	map<int, int> v;
	queue<int> q;

	cin >> num;

	q.push(1);

	v[1] = 1;

	while (!q.empty()) {

		route = q.front();
		q.pop();

		if (route == num) {
			result = v[route];
			break;
		}

		bit_count = get_bit(route);

		v1 = route + bit_count;
		v2 = route - bit_count;

		if ((v1 <= num) && (v[v1] == 0 || v[route] + 1 < v[v1])) {
			v[v1] = v[route] + 1;
			q.push(v1);
		}

		if ((0 < v2) && (v[v2] == 0 || v[route] + 1 < v[v2])) {
			v[v2] = v[route] + 1;
			q.push(v2);
		}

	}

	if (result == 0) {
		cout << -1;
	} else {
		cout << result;
	}

	return 0;

}

inline int main045() {

	int num;
	int *value;
	int **c_value;
	int i;

	cin >> num;

	value = new int[num];
	c_value = new int*[num];

	for (i = 0; i < num; i++) {
		cin >> value[i];
		c_value[i] = new int[2];

	}

	c_value[0][0] = 0;
	c_value[0][1] = value[0];

	if (num > 1) {
		c_value[1][0] = value[0];
		c_value[1][1] = value[1];
	}

	for (i = 2; i < num; i++) {
		c_value[i][0] = max(c_value[i - 1][1], c_value[i - 2][1]);
		c_value[i][1] = max(c_value[i - 1][0] + value[i],
				c_value[i - 2][0] + value[i]);
	}

	cout << max(c_value[num - 1][0], c_value[num - 1][1]);

	return 0;
}
0