結果

問題 No.3 ビットすごろく
ユーザー koinko_gamekoinko_game
提出日時 2019-07-10 23:27:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 925 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 63,624 KB
実行使用メモリ 23,936 KB
最終ジャッジ日時 2023-09-14 01:22:08
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
21,800 KB
testcase_01 AC 56 ms
21,740 KB
testcase_02 AC 57 ms
21,804 KB
testcase_03 AC 58 ms
21,680 KB
testcase_04 AC 57 ms
21,780 KB
testcase_05 AC 60 ms
21,828 KB
testcase_06 AC 58 ms
23,768 KB
testcase_07 AC 57 ms
19,832 KB
testcase_08 AC 60 ms
21,848 KB
testcase_09 AC 62 ms
21,680 KB
testcase_10 AC 65 ms
21,624 KB
testcase_11 AC 63 ms
21,688 KB
testcase_12 AC 61 ms
21,756 KB
testcase_13 AC 56 ms
21,656 KB
testcase_14 AC 65 ms
21,948 KB
testcase_15 AC 67 ms
23,804 KB
testcase_16 AC 66 ms
23,936 KB
testcase_17 AC 66 ms
21,704 KB
testcase_18 AC 57 ms
21,656 KB
testcase_19 AC 66 ms
21,764 KB
testcase_20 AC 56 ms
21,720 KB
testcase_21 AC 56 ms
21,668 KB
testcase_22 AC 64 ms
21,772 KB
testcase_23 AC 68 ms
23,916 KB
testcase_24 AC 67 ms
21,840 KB
testcase_25 AC 66 ms
21,676 KB
testcase_26 AC 56 ms
23,648 KB
testcase_27 AC 58 ms
21,852 KB
testcase_28 AC 66 ms
23,776 KB
testcase_29 AC 62 ms
23,760 KB
testcase_30 AC 57 ms
21,612 KB
testcase_31 AC 58 ms
21,864 KB
testcase_32 AC 61 ms
23,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Program
{
    static int[] dp;
    static int N = 0;
    static void Main(string[] args)
    {
        N = int.Parse(ReadLine());
        dp = Enumerable.Repeat(1000000000, 10001).ToArray();
        dp[1] = 1;
        DFS(1);
        WriteLine(dp[N] == 1000000000 ? -1 : dp[N]);
    }
    static void DFS(int from)
    {
        int delta = 0;
        for (int j = 0; j < 32; j++)
            if (((from >> j) & 1) == 1)
                delta++;

        if(N >= from + delta && dp[from + delta] > dp[from] + 1)
        {
            dp[from + delta] = dp[from] + 1;
            DFS(from + delta);
        }

        if(1 <= from - delta && dp[from - delta] > dp[from] + 1)
        {
            dp[from - delta] = dp[from] + 1;
            DFS(from - delta);
        }
    }
}
0