結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 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 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 105 ms
11,296 KB
testcase_24 AC 81 ms
9,712 KB
testcase_25 AC 91 ms
10,768 KB
testcase_26 AC 86 ms
10,240 KB
testcase_27 AC 296 ms
20,272 KB
testcase_28 AC 80 ms
8,456 KB
testcase_29 AC 275 ms
19,216 KB
testcase_30 AC 168 ms
13,672 KB
testcase_31 AC 305 ms
20,800 KB
testcase_32 AC 354 ms
23,176 KB
testcase_33 AC 168 ms
13,672 KB
testcase_34 AC 195 ms
15,256 KB
testcase_35 AC 244 ms
17,632 KB
testcase_36 AC 167 ms
13,408 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 398 ms
21,856 KB
testcase_40 AC 74 ms
7,884 KB
testcase_41 AC 81 ms
8,392 KB
testcase_42 AC 318 ms
18,688 KB
testcase_43 AC 112 ms
9,976 KB
testcase_44 AC 241 ms
15,256 KB
testcase_45 AC 114 ms
9,976 KB
testcase_46 AC 58 ms
7,188 KB
testcase_47 AC 475 ms
23,704 KB
testcase_48 AC 473 ms
23,704 KB
testcase_49 AC 462 ms
23,704 KB
testcase_50 AC 463 ms
23,704 KB
testcase_51 AC 467 ms
23,704 KB
testcase_52 AC 204 ms
17,896 KB
testcase_53 AC 286 ms
23,176 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 88 ms
10,504 KB
testcase_58 AC 148 ms
14,200 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