結果

問題 No.808 Kaiten Sushi?
ユーザー pekempeypekempey
提出日時 2019-03-22 22:54:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 81,676 KB
実行使用メモリ 23,696 KB
最終ジャッジ日時 2023-10-19 10:09:36
合計ジャッジ時間 10,364 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 104 ms
11,288 KB
testcase_24 AC 82 ms
9,704 KB
testcase_25 AC 91 ms
10,760 KB
testcase_26 AC 87 ms
10,232 KB
testcase_27 AC 288 ms
20,264 KB
testcase_28 AC 79 ms
8,440 KB
testcase_29 AC 273 ms
19,208 KB
testcase_30 AC 170 ms
13,664 KB
testcase_31 AC 307 ms
20,792 KB
testcase_32 AC 358 ms
23,168 KB
testcase_33 AC 168 ms
13,664 KB
testcase_34 AC 195 ms
15,248 KB
testcase_35 AC 240 ms
17,624 KB
testcase_36 AC 162 ms
13,400 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 382 ms
21,848 KB
testcase_40 AC 74 ms
7,856 KB
testcase_41 AC 80 ms
8,384 KB
testcase_42 AC 314 ms
18,680 KB
testcase_43 AC 112 ms
9,968 KB
testcase_44 AC 257 ms
15,248 KB
testcase_45 AC 115 ms
9,968 KB
testcase_46 AC 65 ms
7,160 KB
testcase_47 AC 468 ms
23,696 KB
testcase_48 AC 469 ms
23,696 KB
testcase_49 AC 510 ms
23,696 KB
testcase_50 AC 511 ms
23,696 KB
testcase_51 AC 511 ms
23,696 KB
testcase_52 AC 206 ms
17,888 KB
testcase_53 AC 291 ms
23,168 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 89 ms
10,496 KB
testcase_58 AC 149 ms
14,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0