結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-06-04 14:45:02 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 1,153 bytes |
コンパイル時間 | 11,400 ms |
コンパイル使用メモリ | 234,184 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-01 07:59:13 |
合計ジャッジ時間 | 12,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
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 }