結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
Adamantite
|
| 提出日時 | 2023-06-29 21:19:49 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 2,560 ms / 5,000 ms |
| コード長 | 1,161 bytes |
| コンパイル時間 | 6,613 ms |
| コンパイル使用メモリ | 166,976 KB |
| 実行使用メモリ | 210,220 KB |
| 最終ジャッジ日時 | 2024-07-06 11:25:45 |
| 合計ジャッジ時間 | 31,546 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (81 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
namespace No00003_BitSugoroku
{
internal class Program
{
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] map = new int[n + 1];
map[1] = 1;
Queue<int> q = new Queue<int>();
q.Enqueue(1);
while (0 < q.Count) {
int x = q.Dequeue();
if(x == n) {
break;
}
int diff = Convert.ToString(x, 2).Count(x => x == '1');
if (x + diff <= n) {
if (map[x + diff] == 0 || map[x] < map[x + diff]) {
q.Enqueue(x + diff);
map[x + diff] = map[x] + 1;
}
}
if (0 < x - diff) {
if (map[x - diff] == 0 || map[x] < map[x - diff]) {
q.Enqueue(x - diff);
map[x - diff] = map[x] + 1;
}
}
}
Console.WriteLine(map[n] == 0 ? -1: map[n]);
}
}
}
Adamantite