結果

問題 No.648  お や す み 
ユーザー yukinon0808
提出日時 2018-02-09 23:09:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,121 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 79,572 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-08 22:01:49
合計ジャッジ時間 3,237 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MAX_T 2000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int n;

int sheep(int t) {
    return t * (t + 1) / 2;
}

int my_binary_search(int l, int r) {
    if (r - l == 1) {
        int num_l = sheep(l);
        int num_r = sheep(r);
        if (num_l == n)
            return l;
        else if (num_r == n)
            return r;
        else
            return 0;
    }
    int c = (l + r) / 2;
    int num = sheep(c);
    if (num == n) {
        return c;
    } else if (num > n) {
        return my_binary_search(l, c);
    } else {
        return my_binary_search(c, r);
    }
}

int main() {
    cin >> n;
    
    int l = 0, r = 20;
    
    int ans = my_binary_search(l, r);

    if (ans == 0)
        cout << "NO" << endl;
    else {
        cout << "YES" << endl << ans << endl;
    }
    
    return 0;
}
0