結果

問題 No.1286 Stone Skipping
ユーザー bluemeganebluemegane
提出日時 2020-11-14 10:40:09
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,107 bytes
コンパイル時間 2,355 ms
コンパイル使用メモリ 65,012 KB
実行使用メモリ 24,916 KB
最終ジャッジ日時 2023-09-30 04:47:25
合計ジャッジ時間 3,757 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,664 KB
testcase_01 AC 56 ms
22,668 KB
testcase_02 AC 55 ms
20,840 KB
testcase_03 AC 56 ms
20,756 KB
testcase_04 AC 57 ms
22,768 KB
testcase_05 AC 56 ms
20,708 KB
testcase_06 AC 56 ms
20,648 KB
testcase_07 AC 55 ms
20,596 KB
testcase_08 AC 54 ms
18,620 KB
testcase_09 AC 56 ms
20,844 KB
testcase_10 AC 56 ms
20,656 KB
testcase_11 AC 56 ms
20,624 KB
testcase_12 AC 56 ms
20,592 KB
testcase_13 AC 56 ms
20,652 KB
testcase_14 AC 56 ms
20,744 KB
testcase_15 AC 55 ms
20,772 KB
testcase_16 AC 55 ms
22,728 KB
testcase_17 AC 55 ms
22,804 KB
testcase_18 AC 55 ms
20,752 KB
testcase_19 AC 56 ms
20,692 KB
testcase_20 AC 56 ms
20,716 KB
testcase_21 AC 55 ms
20,840 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 55 ms
20,736 KB
testcase_26 AC 55 ms
22,668 KB
testcase_27 AC 56 ms
22,776 KB
testcase_28 AC 55 ms
20,756 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 + 100; i++)
        {
            if (check1(n, i)) { Console.WriteLine(i); return; }
        }
    }
}
0