結果

問題 No.648  お や す み 
ユーザー nanaenanae
提出日時 2018-02-09 22:27:53
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 97,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 23:49:16
合計ジャッジ時間 3,188 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    long n;
    scan(n);

    long btm = 0, top = n;

    bool check(long m) {
        return m >= (2*n + m) / (m + 1);
    }

    while (top - btm > 1) {
        long mid = btm + (top - btm) / 2;

        if (check(mid)) {
            top = mid;
        }
        else {
            btm = mid;
        }
    }

    if (top*(top+1)/2 == n) {
        writeln("YES");
        writeln(top);
    }
    else {
        writeln("NO");
    }
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0