結果

問題 No.3 ビットすごろく
ユーザー OhashiReonOhashiReon
提出日時 2022-12-23 04:58:15
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 959 bytes
コンパイル時間 4,312 ms
コンパイル使用メモリ 66,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:10:43
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(7, 8) Warning: imported and not used: 'bitops' [UnusedImport]

ソースコード

diff #

#==================================
#
#==================================

import sequtils
import strutils
import bitops
import math
import deques

proc BFS(graph:seq[seq[int]],first:int):seq[int]=
    var isSeen = newSeq[bool](graph.len)
    var queue = newSeq[int]().toDeque
    var distance = newSeqWith(graph.len,-1)
    distance[first] = 1
    queue.addFirst(first)
    while queue.len != 0:
        var a = queue.popFirst()
        isSeen[a] = true
        for i in graph[a]:
            if not isSeen[i]:
                queue.addFirst(i)
                distance[i] = distance[a] + 1
    return distance



proc f(i:int):int = 
    var s = i.toBin(14)
    result = 0
    for value in s:
        if value == '1':
            result += 1


var n = stdin.readLine.parseInt
var graph = newSeqWith(n,newSeq[int]())
for i in 1..n:
    if 0<i-f(i):
        graph[i-1].add(i-f(i)-1)
    if i+f(i)<n+1:
        graph[i-1].add(i+f(i)-1)


echo BFS(graph,0)[n-1]
0