結果

問題 No.3 ビットすごろく
ユーザー ebicochinealebicochineal
提出日時 2016-06-04 14:45:02
言語 Go
(1.22.1)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,153 bytes
コンパイル時間 17,204 ms
コンパイル使用メモリ 205,224 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 00:01:08
合計ジャッジ時間 13,488 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

func main() {
    N := InputInt()
    q := []int{1}
    r := make(map[int]int)
    for i, l := 1, []int{}; len(q) > 0; i, l, q= i+1, nil, l {
        for _, j := range q {
            if j == N {
                Print(i)
                return
            } else if r[j] == 0 {
                r[j] = 1
                b := BinCount(j)
                n, m := j+b, j-b
                if n <= N {l = append(l, n)}
                if m > 0 {l = append(l, m)}
            }
        }
    }
    Print(-1)
}

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