結果

問題 No.808 Kaiten Sushi?
ユーザー TiramisterTiramister
提出日時 2019-03-22 23:07:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 79,468 KB
実行使用メモリ 10,584 KB
最終ジャッジ日時 2023-10-19 10:21:19
合計ジャッジ時間 5,431 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 2 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 2 ms
4,348 KB
testcase_23 AC 45 ms
6,692 KB
testcase_24 AC 37 ms
5,172 KB
testcase_25 AC 41 ms
5,700 KB
testcase_26 AC 39 ms
5,436 KB
testcase_27 AC 117 ms
10,320 KB
testcase_28 AC 35 ms
4,908 KB
testcase_29 AC 110 ms
9,592 KB
testcase_30 AC 57 ms
6,492 KB
testcase_31 AC 100 ms
10,584 KB
testcase_32 AC 117 ms
10,120 KB
testcase_33 AC 58 ms
6,492 KB
testcase_34 AC 65 ms
7,020 KB
testcase_35 AC 82 ms
8,800 KB
testcase_36 AC 58 ms
6,492 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 106 ms
9,328 KB
testcase_40 AC 24 ms
4,644 KB
testcase_41 AC 29 ms
4,908 KB
testcase_42 AC 88 ms
9,328 KB
testcase_43 AC 39 ms
5,436 KB
testcase_44 AC 68 ms
7,020 KB
testcase_45 AC 38 ms
5,436 KB
testcase_46 AC 23 ms
4,380 KB
testcase_47 AC 118 ms
10,384 KB
testcase_48 AC 116 ms
10,384 KB
testcase_49 AC 116 ms
10,384 KB
testcase_50 AC 117 ms
10,384 KB
testcase_51 AC 118 ms
10,384 KB
testcase_52 AC 69 ms
8,800 KB
testcase_53 AC 92 ms
10,120 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 31 ms
5,436 KB
testcase_58 AC 53 ms
6,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using ll = long long;

int main() {
    int N;
    ll L;
    std::cin >> N >> L;

    std::vector<std::pair<ll, int>> pos(N * 2);
    for (int i = 0; i < N; ++i) {
        std::cin >> pos[i].first;
        pos[i].second = 1;
    }
    for (int i = 0; i < N; ++i) {
        std::cin >> pos[i + N].first;
        pos[i + N].second = -1;
    }

    std::sort(pos.begin(), pos.end());
    // 最初の寿司の位置まで移動する
    int bitr = 0;
    while (pos[bitr].second < 0) ++bitr;

    ll buf = pos[bitr].first;  // 最初の寿司までの距離
    for (auto& p : pos) {
        p.first -= buf;
        if (p.first < 0) p.first += L;
    }
    std::sort(pos.begin(), pos.end());
    pos.push_back(pos.front());

    // 寿司のstack(何周目に取るか)
    std::vector<ll> sushi(N * 2 + 1);
    sushi[0] = 0;
    for (int i = 0; i < N * 2; ++i) {
        sushi[i + 1] = sushi[i] + pos[i].second;
    }
    // スタート時点にてstackが正になる場合
    ll min = *std::min_element(sushi.begin(), sushi.end());
    for (auto& s : sushi) s -= min;

    ll ans = 0;
    for (int i = 1; i <= N * 2; ++i) {
        if (pos[i].second < 0) {
            ans = std::max(ans, pos[i].first + L * (sushi[i] - 1));
        }
    }
    std::cout << ans + buf << std::endl;
    return 0;
}
0