結果

問題 No.808 Kaiten Sushi?
ユーザー rpy3cpprpy3cpp
提出日時 2019-03-31 12:50:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,371 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 171,800 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-05-01 09:21:41
合計ジャッジ時間 8,090 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 23 ms
6,912 KB
testcase_24 AC 19 ms
6,528 KB
testcase_25 AC 22 ms
6,912 KB
testcase_26 AC 21 ms
6,784 KB
testcase_27 AC 79 ms
11,136 KB
testcase_28 AC 24 ms
5,888 KB
testcase_29 AC 78 ms
10,880 KB
testcase_30 AC 49 ms
8,192 KB
testcase_31 AC 86 ms
11,648 KB
testcase_32 AC 99 ms
12,544 KB
testcase_33 AC 48 ms
8,064 KB
testcase_34 AC 55 ms
8,832 KB
testcase_35 AC 70 ms
9,984 KB
testcase_36 AC 44 ms
8,192 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 108 ms
11,904 KB
testcase_40 AC 21 ms
5,504 KB
testcase_41 AC 22 ms
5,760 KB
testcase_42 AC 79 ms
10,496 KB
testcase_43 AC 32 ms
6,656 KB
testcase_44 AC 63 ms
8,960 KB
testcase_45 AC 32 ms
6,656 KB
testcase_46 AC 18 ms
5,376 KB
testcase_47 AC 114 ms
12,800 KB
testcase_48 AC 115 ms
12,800 KB
testcase_49 AC 116 ms
12,928 KB
testcase_50 AC 116 ms
12,928 KB
testcase_51 AC 114 ms
12,928 KB
testcase_52 AC 48 ms
10,112 KB
testcase_53 AC 65 ms
12,544 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 22 ms
6,784 KB
testcase_58 AC 35 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

auto find_next_core(int p, set<int> &ps){
    auto it_next = ps.upper_bound(p);
    if (it_next == ps.end()) it_next = ps.begin();
    return it_next;
}

auto find_prev_core(int p, set<int> &ps){
    auto it_next = ps.lower_bound(p);
    if (it_next == ps.begin()) it_next = ps.end();
    auto it_prev = prev(it_next);
    return it_prev;
}

int find_and_erase_next(int y0, set<int> &xs, set<int> &ys) {
    auto it_x = find_next_core(y0, xs);
    auto it_y = find_next_core(*it_x, ys);
    auto it_next = find_prev_core(*it_y, xs);
    int next = *it_next;
    xs.erase(it_next);
    return next;
}

ll solve(int N, int L, set<int> &xs, set<int> &ys){
    ll ans = 0;
    int x = 0;
    int y = 0;
    for (int i = 0; i < N; ++i){
        x = find_and_erase_next(y, xs, ys);
        ans += (x > y) ? (x - y):(L + x - y);
        y = find_and_erase_next(x, ys, xs);
        ans += (y > x) ? (y - x):(L + y - x);
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L;
    cin >> N >> L;
    int x, y;
    set<int> xs, ys;
    for (int i = 0; i < N; ++i){
        cin >> x;
        xs.insert(xs.end(), x);
    }
    for (int i = 0; i < N; ++i){
        cin >> y;
        ys.insert(ys.end(), y);
    }
    cout << solve(N, L, xs, ys) << endl;
    return 0;
}
0