結果
問題 | No.808 Kaiten Sushi? |
ユーザー |
![]() |
提出日時 | 2019-03-22 22:08:55 |
言語 | C++11 (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,056 bytes |
コンパイル時間 | 523 ms |
コンパイル使用メモリ | 65,232 KB |
実行使用メモリ | 814,592 KB |
最終ジャッジ日時 | 2024-09-19 05:36:17 |
合計ジャッジ時間 | 4,192 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 6 RE * 11 MLE * 1 -- * 38 |
ソースコード
#include <iostream> #include <set> #define llint long long using namespace std; llint n, l; set<llint> S, T; llint dist(llint s, llint t) { if(s > t) return t+l - s; else return t-s; } set<llint>::iterator succ(set<llint> &S, llint x) { auto p = S.upper_bound(x); if(p == S.end()) p = S.begin(); return p; } set<llint>::iterator pred(set<llint> &S, llint x) { auto p = S.lower_bound(x); if(p == S.begin()) p = S.end(); p--; return p; } int main(void) { cin >> n >> l; llint x; for(int i = 1; i <= n; i++) cin >> x, S.insert(x); for(int i = 1; i <= n; i++) cin >> x, T.insert(x); llint ans = 0, pos = 0; for(int i = 1; i < n; i++){ auto p = succ(S, pos); p = succ(T, *p); p = pred(S, *p); ans += dist(pos, *p); pos = *p; S.erase(p); p = succ(T, pos); p = succ(S, *p); p = pred(T, *p); ans += dist(pos, *p); pos = *p; T.erase(p); } auto p = succ(S, pos); ans += dist(pos, *p); pos = *p; S.erase(p); p = succ(T, pos); ans += dist(pos, *p); pos = *p; S.erase(p); cout << ans << endl; return 0; }