結果

問題 No.45 回転寿司
ユーザー SotaSota
提出日時 2022-05-27 15:21:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 1,594 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 101,456 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 19:41:53
合計ジャッジ時間 2,410 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 10 ms
4,348 KB
testcase_02 AC 40 ms
4,348 KB
testcase_03 AC 72 ms
4,348 KB
testcase_04 AC 18 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 28 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 21 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 15 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 26 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 6 ms
4,348 KB
testcase_27 AC 22 ms
4,348 KB
testcase_28 AC 5 ms
4,348 KB
testcase_29 AC 20 ms
4,348 KB
testcase_30 AC 23 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 66 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>		//cin, cout
#include <vector>		//vector
#include <algorithm>	//sort,min,max,count
#include <string>		//string,getline, to_string
#include <cstdlib>		//abs(int)
#include <utility>		//swap, pair
#include <deque>		//deque
#include <climits>		//INT_MAX
#include <bitset>		//bitset
#include <cmath>		//sqrt, ceil. M_PI, pow, sin
#include <ios>			//fixed
#include <iomanip>		//setprecision
#include <sstream>		//stringstream
#include <numeric>		//gcd, assumlate
#include <random>		//randam_device
#include <limits>		//numeric_limits

using namespace std;
constexpr long long int D_MOD = 1000000007;

typedef struct {

	int no;
	int sum;
	bool flg;

} stk;

int main() {

	int N;
	cin >> N;

	vector<int> V(N);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}

	vector<int> best_t(N + 1, -1);
	vector<int> best_f(N + 1, -1);

	deque<stk> Q;

	stk now, next;
	now.no = 0;
	now.sum = 0;
	now.flg = true;

	Q.push_back(now);

	while (!Q.empty()) {

		now = Q.front();
		Q.pop_front();

		if (now.flg) {
			if (best_t[now.no] > now.sum) { continue; }
			else { best_t[now.no] = now.sum; }
		}
		else {
			if (best_f[now.no] > now.sum) { continue; }
			else { best_f[now.no] = now.sum; }
		}

		if (now.no >= N) { continue; }

		if (now.flg) {
			next.sum = now.sum + V[now.no];
			next.no = now.no + 1;
			next.flg = false;
			Q.push_back(next);
		}

		next.sum = now.sum;
		next.no = now.no + 1;
		next.flg = true;
		Q.push_back(next);
	}

	if (best_t[N] > best_f[N]) {
		cout << best_t[N] << endl;
	}
	else {
		cout << best_f[N] << endl;
	}

	return 0;

}
0