結果

問題 No.871 かえるのうた
ユーザー nebukuro09nebukuro09
提出日時 2019-08-30 21:43:19
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 1,206 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 125,164 KB
実行使用メモリ 20,964 KB
最終ジャッジ日時 2024-06-22 02:24:50
合計ジャッジ時間 3,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto n = s[0];
    auto k = s[1] - 1;
    auto X = readln.split.map!(to!long).array;
    auto A = readln.split.map!(to!long).array;

    DList!(Tuple!(long, long)) qmin;
    DList!(Tuple!(long, long)) qmax;
    foreach (i; 0..k) qmin.insertBack(tuple(X[i], A[i]));
    foreach (i; k+1..n) qmax.insertBack(tuple(X[i], A[i]));

    int ans = 0;
    DList!(Tuple!(long, long)) que;
    que.insertBack(tuple(X[k], A[k]));

    long mx = -1;
    long mn = 1L << 59;

    while (!que.empty) {
        ans += 1;
        auto t = que.front;
        que.removeFront;
        auto x = t[0];
        auto a = t[1];
        mx = max(mx, x + a);
        mn = min(mn, x - a);
        while (!qmin.empty && qmin.back[0] >= mn) {
            que.insertBack(qmin.back);
            qmin.removeBack;
        }
        while (!qmax.empty && qmax.front[0] <= mx) {
            que.insertBack(qmax.front);
            qmax.removeFront;
        }
    }

    ans.writeln;
}
0