結果

問題 No.3 ビットすごろく
ユーザー 14番14番
提出日時 2016-03-27 19:12:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 2,123 bytes
コンパイル時間 4,270 ms
コンパイル使用メモリ 106,080 KB
実行使用メモリ 22,792 KB
最終ジャッジ日時 2023-09-13 23:47:25
合計ジャッジ時間 7,660 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,772 KB
testcase_01 AC 57 ms
20,656 KB
testcase_02 AC 57 ms
20,664 KB
testcase_03 AC 61 ms
20,772 KB
testcase_04 AC 59 ms
20,904 KB
testcase_05 AC 61 ms
18,640 KB
testcase_06 AC 60 ms
20,688 KB
testcase_07 AC 59 ms
20,904 KB
testcase_08 AC 60 ms
20,752 KB
testcase_09 AC 60 ms
20,868 KB
testcase_10 AC 60 ms
20,896 KB
testcase_11 AC 60 ms
20,872 KB
testcase_12 AC 60 ms
20,788 KB
testcase_13 AC 59 ms
20,740 KB
testcase_14 AC 60 ms
20,696 KB
testcase_15 AC 61 ms
20,788 KB
testcase_16 AC 61 ms
22,736 KB
testcase_17 AC 61 ms
20,748 KB
testcase_18 AC 61 ms
20,752 KB
testcase_19 AC 61 ms
20,744 KB
testcase_20 AC 59 ms
20,608 KB
testcase_21 AC 59 ms
22,772 KB
testcase_22 AC 61 ms
20,732 KB
testcase_23 AC 62 ms
20,824 KB
testcase_24 AC 61 ms
20,780 KB
testcase_25 AC 61 ms
20,740 KB
testcase_26 AC 58 ms
20,852 KB
testcase_27 AC 59 ms
22,792 KB
testcase_28 AC 62 ms
20,756 KB
testcase_29 AC 61 ms
22,648 KB
testcase_30 AC 59 ms
22,708 KB
testcase_31 AC 58 ms
20,672 KB
testcase_32 AC 61 ms
20,740 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.Collections.Generic;
using System.Text;

public class Program
{
    public void Proc(){
        Reader.IsDebug = false;
        int masu = int.Parse(Reader.ReadLine());
        
        Queue<int> task = new Queue<int>();
        
        int[] map = new int[masu+1];
        map[1] = 1;
        task.Enqueue(1);
        while (task.Count > 0)
        {
            int pos = task.Dequeue();
            string str = Convert.ToString(pos, 2);
            int move = 0;
            foreach (char c in str)
            {
                if(c == '1') {
                    move++;
                }
            }
            
            int nextStep = map[pos] + 1;
            if(pos - move > 0) {
                if(map[pos-move] == 0 || map[pos-move] > nextStep) {
                    map[pos-move] = nextStep;
                    task.Enqueue(pos-move);
                } 
            }
            if(pos + move <= masu) {
                if(map[pos+move] == 0 || map[pos+move] > nextStep) {
                    map[pos + move] = nextStep;
                    task.Enqueue(pos + move);
                }
            }
        }
        
        int ans = map[masu];
        if(ans == 0) {
            ans = -1;
        }
        Console.WriteLine(ans);
    }

    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

class Reader
{
    public static bool IsDebug = true;
    
    private static System.IO.StringReader sr;
    
    public static string ReadLine() {
        if(IsDebug) {
            if(sr == null) {
                sr = new System.IO.StringReader(initStr.Trim());
            }
            return sr.ReadLine();
        } else {
            return Console.ReadLine();
        }
    }
    
    public static int[] GetInt(char delimiter = ' ') {
        string[] inpt = ReadLine().Split(delimiter);
        int[] ret = new int[inpt.Length];
        for(int i=0; i<inpt.Length; i++) {
            ret[i] = int.Parse(inpt[i]);
        }
        return ret;
    }
    
    private static string initStr = @"

4


    ";
}

0