結果

問題 No.648  お や す み 
ユーザー silviasetitech
提出日時 2020-03-15 16:17:44
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 74,468 KB
実行使用メモリ 56,204 KB
最終ジャッジ日時 2024-11-25 03:24:24
合計ジャッジ時間 13,351 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 79 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        sheepSleep solver = new sheepSleep();
        solver.solve(1, in, out);
        out.close();
    }

    static class sheepSleep {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            long n = in.nextLong();

            long ng = -1;
            long ok = (int) 1e9;
            while (Math.abs(ok - ng) > 1) {
                long mid = (ok + ng) / 2;
                if (mid * (mid + 1) / 2 >= n) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            if (ok * (ok + 1) / 2 == n) {
                out.println("YES");
                out.println(ok);
            } else {
                out.println("NO");
            }


        }

    }
}

0