結果
問題 | No.808 Kaiten Sushi? |
ユーザー |
|
提出日時 | 2019-03-22 22:54:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 383 ms / 2,000 ms |
コード長 | 1,136 bytes |
コンパイル時間 | 874 ms |
コンパイル使用メモリ | 81,816 KB |
実行使用メモリ | 23,680 KB |
最終ジャッジ日時 | 2024-09-19 06:21:05 |
合計ジャッジ時間 | 8,711 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> using namespace std; int main() { int N; long long L; cin >> N >> L; vector<long long> A(N), B(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; set<long long> a, b; for (int i = 0; i < N; i++) { a.insert(A[i]); a.insert(A[i] + L); b.insert(B[i]); b.insert(B[i] + L); } long long ans = 0; long long x = 0; for (int i = 0; i < N; i++) { { auto it = a.lower_bound(x); ans += *it - x; x = *it % L; auto it2 = b.lower_bound(x); auto it3 = prev(a.lower_bound(*it2)); ans += *it3 - x; x = *it3 % L; a.erase(x); a.erase(x + L); } { if (!a.empty()) { auto it = b.lower_bound(x); ans += *it - x; x = *it % L; auto it2 = a.lower_bound(x); auto it3 = prev(b.lower_bound(*it2)); ans += *it3 - x; x = *it3 % L; b.erase(x); b.erase(x + L); } else { ans += *b.lower_bound(x) - x; } } } cout << ans << '\n'; }