結果
問題 |
No.808 Kaiten Sushi?
|
ユーザー |
![]() |
提出日時 | 2019-03-22 23:07:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 116 ms / 2,000 ms |
コード長 | 1,361 bytes |
コンパイル時間 | 859 ms |
コンパイル使用メモリ | 79,284 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-09-19 06:31:44 |
合計ジャッジ時間 | 5,213 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using ll = long long; int main() { int N; ll L; std::cin >> N >> L; std::vector<std::pair<ll, int>> pos(N * 2); for (int i = 0; i < N; ++i) { std::cin >> pos[i].first; pos[i].second = 1; } for (int i = 0; i < N; ++i) { std::cin >> pos[i + N].first; pos[i + N].second = -1; } std::sort(pos.begin(), pos.end()); // 最初の寿司の位置まで移動する int bitr = 0; while (pos[bitr].second < 0) ++bitr; ll buf = pos[bitr].first; // 最初の寿司までの距離 for (auto& p : pos) { p.first -= buf; if (p.first < 0) p.first += L; } std::sort(pos.begin(), pos.end()); pos.push_back(pos.front()); // 寿司のstack(何周目に取るか) std::vector<ll> sushi(N * 2 + 1); sushi[0] = 0; for (int i = 0; i < N * 2; ++i) { sushi[i + 1] = sushi[i] + pos[i].second; } // スタート時点にてstackが正になる場合 ll min = *std::min_element(sushi.begin(), sushi.end()); for (auto& s : sushi) s -= min; ll ans = 0; for (int i = 1; i <= N * 2; ++i) { if (pos[i].second < 0) { ans = std::max(ans, pos[i].first + L * (sushi[i] - 1)); } } std::cout << ans + buf << std::endl; return 0; }