結果

問題 No.3 ビットすごろく
ユーザー ebicochinealebicochineal
提出日時 2016-06-04 14:14:12
言語 Go
(1.22.1)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,279 bytes
コンパイル時間 12,753 ms
コンパイル使用メモリ 215,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 00:00:23
合計ジャッジ時間 14,410 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main() {
    N := InputInt()
    ans := -1
    q := []int{1}
    var r [100001]int
    c := 1
    for len(q) > 0 {
        var l []int
        for _, i := range q {
            if i == N {
                ans = c
                l = nil
                break
            } else if r[i] == 0 {
                r[i] = 1
                b := BinCount(i)
                n, m := i+b, i-b
                if n <= N {
                    l = append(l, n)
                }
                if m > 0 {
                    l = append(l, m)
                }
            }
        }
        q = l
        c += 1
    }
    Print(ans)
}

func Print(x ...interface{}){
    l := len(x) + 1
    for ii, vi := range x {
        fmt.Print(vi)
        if ii == l {
            fmt.Print(" ")
        } else {
            fmt.Print("\n")
        }
    }
}
var sc = bufio.NewScanner(os.Stdin)
func Input() string {
    sc.Scan()
    return sc.Text()
}
func InputInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}
func BinCount(x int) int {
    s := fmt.Sprintf("%b", x)
    c := 0
    for _, i := range s {
        if i == '1' {c += 1}
    }
    return c
}
0