結果

問題 No.871 かえるのうた
ユーザー nebukuro09nebukuro09
提出日時 2019-08-30 21:47:48
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,213 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 124,860 KB
実行使用メモリ 21,212 KB
最終ジャッジ日時 2024-06-22 02:25:01
合計ジャッジ時間 3,478 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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 = -(10L^^18);
    long mn = 10L^^18;

    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