結果

問題 No.1869 Doubling?
ユーザー bluemeganebluemegane
提出日時 2022-03-12 10:40:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 2,717 ms
コンパイル使用メモリ 67,732 KB
実行使用メモリ 25,404 KB
最終ジャッジ日時 2023-10-14 22:37:06
合計ジャッジ時間 6,804 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,532 KB
testcase_01 AC 63 ms
23,420 KB
testcase_02 AC 64 ms
21,412 KB
testcase_03 AC 63 ms
21,396 KB
testcase_04 AC 64 ms
21,428 KB
testcase_05 AC 64 ms
21,584 KB
testcase_06 AC 63 ms
23,544 KB
testcase_07 AC 64 ms
23,356 KB
testcase_08 AC 64 ms
21,536 KB
testcase_09 AC 86 ms
22,192 KB
testcase_10 AC 64 ms
25,404 KB
testcase_11 AC 68 ms
22,176 KB
testcase_12 AC 68 ms
22,212 KB
testcase_13 AC 68 ms
24,092 KB
testcase_14 AC 68 ms
22,104 KB
testcase_15 AC 63 ms
19,384 KB
testcase_16 AC 65 ms
23,452 KB
testcase_17 AC 63 ms
21,332 KB
testcase_18 AC 63 ms
21,456 KB
testcase_19 AC 62 ms
21,444 KB
testcase_20 AC 63 ms
21,400 KB
testcase_21 AC 63 ms
21,468 KB
testcase_22 AC 64 ms
21,312 KB
testcase_23 AC 63 ms
23,512 KB
testcase_24 AC 63 ms
23,388 KB
testcase_25 AC 63 ms
21,448 KB
testcase_26 AC 63 ms
23,416 KB
testcase_27 AC 66 ms
21,524 KB
testcase_28 AC 62 ms
19,308 KB
testcase_29 AC 63 ms
21,440 KB
testcase_30 AC 63 ms
23,568 KB
testcase_31 AC 63 ms
21,364 KB
testcase_32 AC 62 ms
21,580 KB
testcase_33 AC 63 ms
21,612 KB
testcase_34 AC 63 ms
21,360 KB
testcase_35 AC 63 ms
21,416 KB
testcase_36 AC 64 ms
23,492 KB
testcase_37 AC 64 ms
23,540 KB
testcase_38 AC 64 ms
19,460 KB
testcase_39 AC 68 ms
22,004 KB
testcase_40 AC 70 ms
24,076 KB
testcase_41 AC 68 ms
22,080 KB
testcase_42 AC 64 ms
23,572 KB
testcase_43 AC 63 ms
21,600 KB
testcase_44 AC 68 ms
23,840 KB
testcase_45 AC 63 ms
21,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = long.Parse(line[1]);
        getAns(n, m);
    }
    static void getAns(int n, long m)
    {
        var m2 = m;
        var ans = new List<long>();
        ans.Add(m2);
        while (m2 > 1)
        {
            m2 = m2 % 2 == 0 ? m2 / 2 : (m2 + 1) / 2;
            ans.Add(m2);
        }
        if (ans.Count > n)
        {
            var ans2 = ans.OrderBy(x => x).Take(n).Sum();
            var pow2 = (int)Pow(2, n - 1);
            if (pow2 < m) Console.WriteLine(Max(pow2 * 2 -1,ans2));
            else Console.WriteLine(ans2);
            return;
        }
        var res = ans.Sum();
        res += n - ans.Count;
        Console.WriteLine(res);
    }
}
0