結果

問題 No.3 ビットすごろく
ユーザー バカらっくバカらっく
提出日時 2017-06-25 14:45:07
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 1,588 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 108,088 KB
実行使用メモリ 23,704 KB
最終ジャッジ日時 2023-09-14 00:46:18
合計ジャッジ時間 5,808 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
21,644 KB
testcase_01 AC 56 ms
21,508 KB
testcase_02 AC 57 ms
21,688 KB
testcase_03 AC 60 ms
21,628 KB
testcase_04 AC 56 ms
19,544 KB
testcase_05 AC 59 ms
21,548 KB
testcase_06 AC 57 ms
23,588 KB
testcase_07 AC 57 ms
21,480 KB
testcase_08 AC 56 ms
21,476 KB
testcase_09 AC 58 ms
21,548 KB
testcase_10 AC 61 ms
21,580 KB
testcase_11 AC 60 ms
23,624 KB
testcase_12 AC 60 ms
21,488 KB
testcase_13 AC 57 ms
21,516 KB
testcase_14 AC 61 ms
21,652 KB
testcase_15 AC 61 ms
21,476 KB
testcase_16 AC 59 ms
23,592 KB
testcase_17 AC 62 ms
21,516 KB
testcase_18 AC 56 ms
19,624 KB
testcase_19 AC 59 ms
19,672 KB
testcase_20 AC 55 ms
21,580 KB
testcase_21 AC 59 ms
21,464 KB
testcase_22 AC 66 ms
21,572 KB
testcase_23 AC 65 ms
21,628 KB
testcase_24 AC 63 ms
23,512 KB
testcase_25 AC 62 ms
21,488 KB
testcase_26 AC 60 ms
21,572 KB
testcase_27 AC 62 ms
23,644 KB
testcase_28 AC 62 ms
21,480 KB
testcase_29 AC 59 ms
21,560 KB
testcase_30 AC 57 ms
21,520 KB
testcase_31 AC 58 ms
21,476 KB
testcase_32 AC 60 ms
23,704 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int num = int.Parse(Reader.ReadLine());

        int[] map = new int[num + 1];
        map[1] = 1;
        Queue<int> q = new Queue<int>();
        q.Enqueue(1);
        while(q.Count()>0) {
            int cur = q.Dequeue();
            int step = map[cur];
            int move = Convert.ToString(cur, 2).Count(a => a == '1');
            int[] nextPos = new int[] { cur - move, cur + move };
            foreach(int next in nextPos) {
                if(next<=1) {
                    continue;
                }
                if(next>num) {
                    continue;
                }
                if(map[next]==0||map[next]>step+1) {
                    map[next] = step + 1;
                    q.Enqueue(next);
                }
            }
        }
        if(map[num]==0) {
            Console.WriteLine(-1);
        } else {
            Console.WriteLine(map[num]);
        }
    
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"





5




";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}
0