結果
問題 | No.484 収穫 |
ユーザー | tansunogon |
提出日時 | 2017-05-05 17:45:25 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,086 ms / 3,000 ms |
コード長 | 2,017 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 85,388 KB |
実行使用メモリ | 99,600 KB |
最終ジャッジ日時 | 2024-10-13 13:17:08 |
合計ジャッジ時間 | 13,389 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 904 ms
57,996 KB |
testcase_13 | AC | 1,864 ms
99,600 KB |
testcase_14 | AC | 994 ms
65,244 KB |
testcase_15 | AC | 342 ms
50,848 KB |
testcase_16 | AC | 856 ms
71,264 KB |
testcase_17 | AC | 3 ms
5,248 KB |
testcase_18 | AC | 3 ms
5,248 KB |
testcase_19 | AC | 2,081 ms
96,212 KB |
testcase_20 | AC | 2,066 ms
96,128 KB |
testcase_21 | AC | 2,086 ms
96,216 KB |
testcase_22 | AC | 664 ms
56,080 KB |
testcase_23 | AC | 3 ms
5,248 KB |
ソースコード
#include <iostream> using namespace std; struct iostream_init_struct { iostream_init_struct() { std::cin.tie(0); std::cin.sync_with_stdio(false); } } iostream_init; #include <queue> #include <set> #include <utility> #include <algorithm> int N; int A[2000]; enum Position { LEFT, RIGHT }; class Agent { public: int time; int left; int right; Position place; Agent(int time, int left, int right, Position place) : time(time), left(left), right(right), place(place) {} Agent nextRight() const { int next_time; int next_left = left; int next_right = right - 1; Position next_place = RIGHT; if (place == RIGHT) { next_time = max(time, A[right]) + 1; } else { next_time = max(time + right - left, A[right]) + 1; } return Agent(next_time, next_left, next_right, next_place); } Agent nextLeft() const { int next_time; int next_left = left + 1; int next_right = right; Position next_place = LEFT; if (place == RIGHT) { next_time = max(time + right - left, A[left]) + 1; } else { next_time = max(time, A[left]) + 1; } return Agent(next_time, next_left, next_right, next_place); } bool finished() const { return left >= right; } int finalTime() const { return max(time, A[left]); } int toInt() const { return left + 10000 * (right + 10000 * place); } bool operator<(const Agent& rhs) const { return this->time > rhs.time; } }; priority_queue<Agent> que; set<int> visitedSet; int main(void) { cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i]; } que.push(Agent(/*time*/0, /*left*/0, /*right*/N - 1, RIGHT)); que.push(Agent(/*time*/0, /*left*/0, /*right*/N - 1, LEFT)); while (true) { Agent agent(que.top()); que.pop(); int hash = agent.toInt(); if (visitedSet.find(hash) != visitedSet.end()) { continue; } visitedSet.insert(hash); if (agent.finished()) { cout << agent.finalTime() << endl; return 0; } que.push(agent.nextRight()); que.push(agent.nextLeft()); } }