結果

問題 No.808 Kaiten Sushi?
コンテスト
ユーザー WutongDeath
提出日時 2025-12-22 02:18:47
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,047 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 569 ms
コンパイル使用メモリ 67,716 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-22 02:18:51
合計ジャッジ時間 3,758 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     scanf("%d%d", &n, &l);
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:19:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |     for (int i = 0; i < n; ++i) scanf("%d", &x[i]);
      |                                 ~~~~~^~~~~~~~~~~~~
main.cpp:20:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |     for (int i = 0; i < n; ++i) scanf("%d", &y[i]);
      |                                 ~~~~~^~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>

using namespace std;

typedef long long LL;

const int N = 100010;

struct Event {
    int pos, type;
};

int n, l, x[N], y[N], cur, ma, mi, last, nxt, p, laps;
LL ans;
Event events[N * 2];

int main() {
    scanf("%d%d", &n, &l);
    for (int i = 0; i < n; ++i) scanf("%d", &x[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &y[i]);

    int xi = 0, yi = 0, idx = 0;
    while (xi < n || yi < n) {
        if (xi == n) events[idx++] = { y[yi++], -1 };
        else if (yi == n) events[idx++] = { x[xi++], 1 };
        else if (x[xi] < y[yi]) events[idx++] = { x[xi++], 1 };
        else events[idx++] = { y[yi++], -1 };
    }
    cur = ma = 0, mi = n;
    last = -1;
    for (int i = 0; i < n * 2; ++i) {
        cur += events[i].type;
        if (cur >= ma) {
            ma = cur;
            last = i;
        }
        if (cur <= mi) mi = cur;
    }
    nxt = (last + 1) % (n * 2);
    p = events[nxt].pos;
    laps = ma - mi - (ma > 0 ? 1 : 0);
    ans = 1LL * laps * l + p;
    printf("%lld\n", ans);

    return 0;
}
0