結果

問題 No.648  お や す み 
ユーザー Ryu
提出日時 2018-04-05 17:42:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 166,908 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 21:23:35
合計ジャッジ時間 3,622 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct
{
    int to;
    int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll N;

ll check(ll t)
{
    return t * (t + 1) / 2;
}

int main()
{
    cin >> N;

    ll ng = 0, ok = 1e10;

    while (ok - ng > 1)
    {
        ll mid = (ng + ok) / 2;

        (N <= check(mid) ? ok : ng) = mid;
    }

    if (check(ok) == N)
        cout << "YES\n" << ok << endl;
    else
        cout << "NO" << endl;

    return 0;
}
0