結果

問題 No.648  お や す み 
ユーザー denderaKawazudenderaKawazu
提出日時 2018-02-09 23:49:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,503 bytes
コンパイル時間 2,379 ms
コンパイル使用メモリ 73,848 KB
実行使用メモリ 56,116 KB
最終ジャッジ日時 2023-10-11 22:13:30
合計ジャッジ時間 15,446 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,552 KB
testcase_01 AC 126 ms
55,836 KB
testcase_02 AC 126 ms
55,756 KB
testcase_03 AC 126 ms
55,680 KB
testcase_04 AC 125 ms
55,572 KB
testcase_05 AC 129 ms
55,236 KB
testcase_06 AC 126 ms
55,756 KB
testcase_07 AC 127 ms
54,276 KB
testcase_08 AC 125 ms
55,392 KB
testcase_09 AC 126 ms
55,652 KB
testcase_10 AC 127 ms
55,764 KB
testcase_11 AC 126 ms
55,240 KB
testcase_12 AC 125 ms
55,228 KB
testcase_13 AC 126 ms
55,684 KB
testcase_14 AC 125 ms
55,772 KB
testcase_15 AC 128 ms
55,784 KB
testcase_16 AC 126 ms
55,308 KB
testcase_17 AC 127 ms
55,332 KB
testcase_18 AC 127 ms
55,872 KB
testcase_19 AC 126 ms
55,688 KB
testcase_20 AC 126 ms
55,304 KB
testcase_21 AC 127 ms
55,240 KB
testcase_22 AC 129 ms
55,672 KB
testcase_23 AC 127 ms
55,800 KB
testcase_24 AC 126 ms
55,564 KB
testcase_25 AC 126 ms
55,300 KB
testcase_26 AC 127 ms
55,532 KB
testcase_27 AC 130 ms
55,964 KB
testcase_28 AC 129 ms
55,540 KB
testcase_29 AC 129 ms
55,764 KB
testcase_30 AC 127 ms
55,496 KB
testcase_31 AC 128 ms
55,732 KB
testcase_32 AC 126 ms
55,784 KB
testcase_33 AC 127 ms
55,872 KB
testcase_34 AC 127 ms
55,556 KB
testcase_35 AC 128 ms
55,560 KB
testcase_36 AC 128 ms
55,716 KB
testcase_37 AC 127 ms
55,544 KB
testcase_38 AC 125 ms
55,400 KB
testcase_39 AC 126 ms
55,976 KB
testcase_40 AC 127 ms
55,876 KB
testcase_41 AC 127 ms
55,984 KB
testcase_42 AC 126 ms
55,456 KB
testcase_43 AC 126 ms
55,504 KB
testcase_44 AC 125 ms
55,428 KB
testcase_45 AC 127 ms
55,568 KB
testcase_46 AC 127 ms
55,496 KB
testcase_47 AC 128 ms
55,776 KB
testcase_48 AC 128 ms
55,520 KB
testcase_49 AC 129 ms
55,976 KB
testcase_50 AC 127 ms
55,772 KB
testcase_51 AC 127 ms
55,300 KB
testcase_52 AC 126 ms
55,660 KB
testcase_53 AC 126 ms
55,556 KB
testcase_54 AC 127 ms
55,704 KB
testcase_55 AC 127 ms
56,012 KB
testcase_56 AC 126 ms
55,544 KB
testcase_57 AC 127 ms
55,756 KB
testcase_58 AC 126 ms
55,448 KB
testcase_59 AC 128 ms
55,236 KB
testcase_60 AC 127 ms
55,684 KB
testcase_61 AC 126 ms
55,700 KB
testcase_62 AC 127 ms
55,636 KB
testcase_63 AC 127 ms
55,424 KB
testcase_64 AC 125 ms
55,476 KB
testcase_65 AC 127 ms
55,560 KB
testcase_66 AC 126 ms
55,692 KB
testcase_67 AC 127 ms
55,560 KB
testcase_68 AC 129 ms
55,316 KB
testcase_69 AC 126 ms
55,244 KB
testcase_70 AC 126 ms
56,116 KB
testcase_71 AC 127 ms
56,000 KB
testcase_72 AC 127 ms
55,620 KB
testcase_73 AC 127 ms
55,816 KB
testcase_74 AC 126 ms
53,852 KB
testcase_75 AC 126 ms
55,516 KB
testcase_76 AC 126 ms
55,812 KB
testcase_77 AC 127 ms
53,672 KB
testcase_78 AC 127 ms
55,408 KB
testcase_79 AC 128 ms
55,452 KB
testcase_80 AC 125 ms
55,548 KB
testcase_81 AC 128 ms
55,524 KB
testcase_82 AC 128 ms
55,704 KB
testcase_83 AC 127 ms
55,556 KB
権限があれば一括ダウンロードができます

ソースコード

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
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long maxN = n;
            long minN = 0;
            long cn = -1;

            if (n == 1) {
                out.println("YES");
                out.println(1);
                return;
            }

            while ((maxN + minN) / 2 != cn) {
                cn = (maxN + minN) / 2;
                double sum = (double) cn * ((double) cn + 1) / 2;
                if (sum == n) {
                    break;
                } else if (sum > n) {
                    maxN = cn;
                } else if (sum < n) {
                    minN = cn;
                }
            }

            if (cn * (cn + 1) / 2 == n) {
                out.println("YES");
                out.println(cn);
            } else {
                out.println("NO");
            }
        }

    }
}

0