結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-03 15:38:17 |
| 言語 | Go (1.23.4) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 820 bytes |
| コンパイル時間 | 13,738 ms |
| コンパイル使用メモリ | 237,124 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-13 09:01:12 |
| 合計ジャッジ時間 | 12,226 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
package main
import (
"fmt"
"strconv"
)
func scan() (N int) {
fmt.Scan(&N)
return
}
func countBit(i int) (count int) {
s := strconv.FormatInt(int64(i), 2)
for _, c := range s {
if c == '1' {
count++
}
}
return count
}
func getCount(i int, matrix []bool, N int, count int) int {
if i == N {
return count
}
if i < 1 || i > N || matrix[i] == true {
return -1
}
count++
matrix[i] = true
step := countBit(i)
fowardStep := i + step
backwardStep := i - step
fowardCount := getCount(fowardStep, matrix, N, count)
backwardCount := getCount(backwardStep, matrix, N, count)
if fowardCount > backwardCount {
return fowardCount
} else {
return backwardCount
}
}
func main() {
var N int
N = scan()
// N = 11
matrix := make([]bool, N)
res := getCount(1, matrix, N, 1)
fmt.Print(res)
}