結果

問題 No.1286 Stone Skipping
ユーザー bluemeganebluemegane
提出日時 2020-11-14 11:38:48
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,102 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 63,300 KB
実行使用メモリ 27,196 KB
最終ジャッジ日時 2023-09-30 04:49:12
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
27,196 KB
testcase_01 AC 57 ms
20,756 KB
testcase_02 AC 57 ms
20,684 KB
testcase_03 AC 56 ms
22,724 KB
testcase_04 AC 56 ms
20,680 KB
testcase_05 AC 56 ms
18,712 KB
testcase_06 AC 56 ms
20,736 KB
testcase_07 AC 56 ms
22,660 KB
testcase_08 AC 56 ms
20,840 KB
testcase_09 AC 57 ms
22,732 KB
testcase_10 AC 56 ms
20,632 KB
testcase_11 AC 57 ms
22,772 KB
testcase_12 AC 57 ms
20,684 KB
testcase_13 AC 57 ms
20,672 KB
testcase_14 AC 56 ms
18,608 KB
testcase_15 AC 57 ms
20,772 KB
testcase_16 AC 57 ms
20,592 KB
testcase_17 AC 55 ms
18,616 KB
testcase_18 AC 56 ms
20,684 KB
testcase_19 AC 56 ms
20,648 KB
testcase_20 AC 56 ms
22,764 KB
testcase_21 AC 56 ms
20,732 KB
testcase_22 AC 56 ms
20,724 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

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 <= n; i++)
        {
            if (check1(n, i)) { Console.WriteLine(i); return; }
        }
    }
}
0