結果

問題 No.484 収穫
ユーザー tansunogontansunogon
提出日時 2017-05-05 17:45:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,246 ms / 3,000 ms
コード長 2,017 bytes
コンパイル時間 1,189 ms
コンパイル使用メモリ 85,616 KB
実行使用メモリ 101,464 KB
最終ジャッジ日時 2024-12-25 14:18:48
合計ジャッジ時間 14,705 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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());
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0