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