結果
問題 | No.3 ビットすごろく |
ユーザー | iwkjosec |
提出日時 | 2018-06-29 21:28:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 60 ms / 5,000 ms |
コード長 | 1,413 bytes |
コンパイル時間 | 3,567 ms |
コンパイル使用メモリ | 105,736 KB |
実行使用メモリ | 22,760 KB |
最終ジャッジ日時 | 2023-09-14 01:04:21 |
合計ジャッジ時間 | 6,147 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
20,740 KB |
testcase_01 | AC | 57 ms
20,660 KB |
testcase_02 | AC | 57 ms
20,672 KB |
testcase_03 | AC | 59 ms
22,668 KB |
testcase_04 | AC | 58 ms
20,668 KB |
testcase_05 | AC | 60 ms
20,648 KB |
testcase_06 | AC | 59 ms
20,652 KB |
testcase_07 | AC | 59 ms
20,836 KB |
testcase_08 | AC | 58 ms
20,704 KB |
testcase_09 | AC | 59 ms
20,652 KB |
testcase_10 | AC | 60 ms
22,696 KB |
testcase_11 | AC | 59 ms
22,632 KB |
testcase_12 | AC | 59 ms
20,660 KB |
testcase_13 | AC | 59 ms
20,644 KB |
testcase_14 | AC | 59 ms
20,676 KB |
testcase_15 | AC | 59 ms
20,792 KB |
testcase_16 | AC | 59 ms
20,652 KB |
testcase_17 | AC | 59 ms
20,712 KB |
testcase_18 | AC | 57 ms
20,648 KB |
testcase_19 | AC | 58 ms
20,748 KB |
testcase_20 | AC | 58 ms
20,640 KB |
testcase_21 | AC | 56 ms
20,716 KB |
testcase_22 | AC | 60 ms
22,632 KB |
testcase_23 | AC | 59 ms
18,620 KB |
testcase_24 | AC | 59 ms
20,632 KB |
testcase_25 | AC | 59 ms
20,644 KB |
testcase_26 | AC | 56 ms
18,640 KB |
testcase_27 | AC | 59 ms
22,760 KB |
testcase_28 | AC | 59 ms
20,716 KB |
testcase_29 | AC | 59 ms
22,644 KB |
testcase_30 | AC | 58 ms
20,652 KB |
testcase_31 | AC | 57 ms
20,616 KB |
testcase_32 | AC | 59 ms
20,716 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var N = int.Parse(ReadLine()); var g = new List<int>[N]; for (int i = 0; i < N; i++) { g[i] = new List<int>(); } for (int i = 0; i < N; i++) { var r = BitCount(i + 1); if (i - r >= 0) g[i].Add(i - r); if (i + r < N) g[i].Add(i + r); } WriteLine(BFS(g)); } static int BitCount(int n) { n = (n & 0x55555555) + (n >> 1 & 0x55555555); n = (n & 0x33333333) + (n >> 2 & 0x33333333); n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f); n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff); return (n & 0x0000ffff) + (n >> 16 & 0x0000ffff); } static int BFS(List<int>[] graph) { var q = new Queue<int>(); q.Enqueue(0); var dist = new int[graph.Length]; dist[0]=1; while (q.Count != 0) { var v = q.Dequeue(); if (v == graph.Length - 1) return dist[graph.Length - 1]; foreach (var vertex in graph[v]) { if (dist[vertex]==0) { dist[vertex] = dist[v] + 1; q.Enqueue(vertex); } } } return -1; } }