結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2022-05-27 15:21:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 5,000 ms |
| コード長 | 1,594 bytes |
| コンパイル時間 | 896 ms |
| コンパイル使用メモリ | 101,632 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-20 15:15:07 |
| 合計ジャッジ時間 | 2,196 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#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;
}