結果

問題 No.3 ビットすごろく
コンテスト
ユーザー ebicochineal
提出日時 2016-06-04 14:45:02
言語 Go
(1.26.1)
コンパイル:
env GOCACHE=/tmp go build _filename_
実行:
./Main
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,153 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,278 ms
コンパイル使用メモリ 279,716 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-22 04:19:24
合計ジャッジ時間 11,361 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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