結果
問題 | No.808 Kaiten Sushi? |
ユーザー |
![]() |
提出日時 | 2019-03-22 21:40:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 218 ms / 2,000 ms |
コード長 | 1,021 bytes |
コンパイル時間 | 738 ms |
コンパイル使用メモリ | 72,800 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-09-19 02:59:06 |
合計ジャッジ時間 | 7,690 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <set> #include <iostream> using namespace std; int main() { int N, L; cin >> N >> L; set<int> s, t; for (int i = 0; i < N; ++i) { int x; cin >> x; s.insert(x); } for (int i = 0; i < N; ++i) { int y; cin >> y; t.insert(y); } long long pos = 0; for (int i = 0; i < N; ++i) { set<int>::iterator it = s.lower_bound(pos % L); if (it != s.end()) pos += *it - pos % L, s.erase(it); else pos += *s.begin() % L - pos % L + L, s.erase(s.begin()); if (i + 1 == N) { pos += (*t.begin() - pos % L + L) % L; } else { long long nxt = pos; it = t.lower_bound(nxt % L); if (it != t.end()) nxt += *it - nxt % L; else nxt += *t.begin() - nxt % L + L; it = s.lower_bound(nxt % L); if (it != s.end()) nxt += *it - nxt % L; else nxt += *s.begin() - nxt % L + L; it = t.lower_bound(nxt % L); if (it != t.begin()) --it, pos = nxt - (nxt % L - *it), t.erase(it); else it = --t.end(), pos = nxt - (nxt % L - *it + L), t.erase(it); } } cout << pos << endl; return 0; }