結果

問題 No.1286 Stone Skipping
ユーザー bluemeganebluemegane
提出日時 2020-11-14 10:44:42
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,108 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 60,532 KB
実行使用メモリ 22,816 KB
最終ジャッジ日時 2023-09-30 04:47:32
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
22,724 KB
testcase_01 AC 56 ms
20,728 KB
testcase_02 AC 56 ms
20,688 KB
testcase_03 AC 57 ms
20,768 KB
testcase_04 AC 55 ms
18,676 KB
testcase_05 AC 56 ms
20,652 KB
testcase_06 AC 56 ms
20,756 KB
testcase_07 AC 56 ms
22,692 KB
testcase_08 AC 57 ms
20,764 KB
testcase_09 AC 56 ms
20,624 KB
testcase_10 AC 57 ms
20,732 KB
testcase_11 AC 56 ms
20,744 KB
testcase_12 AC 56 ms
20,616 KB
testcase_13 AC 56 ms
22,788 KB
testcase_14 AC 56 ms
20,568 KB
testcase_15 AC 56 ms
20,636 KB
testcase_16 AC 57 ms
20,724 KB
testcase_17 AC 56 ms
20,776 KB
testcase_18 AC 57 ms
22,700 KB
testcase_19 AC 56 ms
20,628 KB
testcase_20 AC 57 ms
20,768 KB
testcase_21 AC 57 ms
22,720 KB
testcase_22 AC 57 ms
20,824 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 56 ms
20,844 KB
testcase_26 AC 57 ms
20,764 KB
testcase_27 AC 57 ms
22,784 KB
testcase_28 AC 57 ms
22,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;

public class Hello
{
    static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        getAns(n);
    }
    static bool check1(long n, long t)
    {
        var sum = t;
        if (sum == n) { return true; }
        while (true)
        {
            t /= 2;
            sum += t;
            if (sum == n) { return true; }
            if (t == 1) break;
        }
        return false;
    }
    static bool check0(long n, long t)
    {
        var sum = t;
        while (true)
        {
            t /= 2;
            sum += t;
            if (t == 1) break;
        }
        return sum >= n;
    }
    static long getNum(long n)
    {
        var ok = n;
        var ng = 1L;
        while (ok - ng > 1)
        {
            var mid = ng + (ok - ng) / 2;
            if (check0(n, mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    static void getAns(long n)
    {
        var c = getNum(n);
        for (long i = c; i < c + 1000; i++)
        {
            if (check1(n, i)) { Console.WriteLine(i); return; }
        }
    }
}
0