結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2015-12-29 14:33:40 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 26 ms / 5,000 ms |
コード長 | 1,393 bytes |
コンパイル時間 | 901 ms |
コンパイル使用メモリ | 111,268 KB |
実行使用メモリ | 25,876 KB |
最終ジャッジ日時 | 2024-07-01 07:38:55 |
合計ジャッジ時間 | 2,671 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
コンパイルメッセージ
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; namespace yukicoder { class _003 { static void Main() { int n = int.Parse(Console.ReadLine()); int[] dp = new int[n]; dp[0] = 1; Queue<int> q = new Queue<int>(); q.Enqueue(0); while (q.Count > 0) { int p = q.Dequeue(); int m = bit(p + 1); for (int i = -m; i <= m; i += 2 * m) { int t = p + i; if (t > 0 && t < n && dp[t] == 0) { dp[t] = dp[p] + 1; if(t == n - 1) { q.Clear(); continue; } q.Enqueue(p + i); } } } if (dp[n - 1] != 0) { Console.WriteLine(dp[n - 1]); } else { Console.WriteLine("-1"); } Console.ReadLine(); } static int bit(int n) { int ret = 0; while (n > 0) { n &= n - 1; ret++; } return ret; } } }