結果

問題 No.1286 Stone Skipping
ユーザー bluemeganebluemegane
提出日時 2020-11-14 16:13:15
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 985 ms
コンパイル使用メモリ 63,308 KB
実行使用メモリ 22,804 KB
最終ジャッジ日時 2023-09-30 16:12:14
合計ジャッジ時間 3,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,628 KB
testcase_01 AC 55 ms
20,680 KB
testcase_02 AC 56 ms
20,592 KB
testcase_03 AC 56 ms
18,660 KB
testcase_04 AC 55 ms
20,632 KB
testcase_05 AC 55 ms
22,656 KB
testcase_06 AC 55 ms
20,724 KB
testcase_07 AC 55 ms
20,752 KB
testcase_08 AC 56 ms
20,584 KB
testcase_09 AC 55 ms
20,720 KB
testcase_10 AC 55 ms
20,744 KB
testcase_11 AC 55 ms
20,628 KB
testcase_12 AC 56 ms
18,720 KB
testcase_13 AC 56 ms
20,648 KB
testcase_14 AC 57 ms
22,804 KB
testcase_15 AC 57 ms
22,652 KB
testcase_16 AC 57 ms
20,692 KB
testcase_17 AC 57 ms
20,652 KB
testcase_18 AC 56 ms
20,720 KB
testcase_19 AC 55 ms
20,708 KB
testcase_20 AC 57 ms
20,532 KB
testcase_21 AC 56 ms
18,636 KB
testcase_22 AC 55 ms
22,692 KB
testcase_23 AC 56 ms
20,672 KB
testcase_24 AC 57 ms
18,600 KB
testcase_25 AC 56 ms
20,604 KB
testcase_26 AC 57 ms
20,756 KB
testcase_27 AC 57 ms
18,680 KB
testcase_28 AC 57 ms
18,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        getAns(n);
    }
    static void getAns (long n)
    {
        var ans = long.MaxValue;
        for (int k = 0; k < 65; k++)
        {
            var w = BS(n, k);
            if (w != -1) ans = Min(ans, w);
        }
        Console.WriteLine(ans == long.MaxValue?  n:ans);
    }
    static long BS (long targ, int k)
    {
        var ng = 1L;
        var ok = targ;
        while (ok - ng > 1)
        {
            var mid = ng + (ok - ng) / 2;
            var w = calc(mid, k);
            if (w == targ) return mid;
            else if (w > targ) ok = mid;
            else ng = mid;
        }
        return -1;
    }
    static long calc (long n , int k)
    {
        var res = n;
        var p = 1;
        while (p < k && n >0)
        {
            n /= 2;
            res += n;
            p++;
        }
        return res;
    }
}
0