結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2022-12-23 04:58:15 |
言語 | Nim (2.2.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 959 bytes |
コンパイル時間 | 2,811 ms |
コンパイル使用メモリ | 66,956 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-18 03:54:44 |
合計ジャッジ時間 | 3,731 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(7, 8) Warning: imported and not used: 'bitops' [UnusedImport]
ソースコード
#================================== # #================================== 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]