結果
| 問題 |
No.3 ビットすごろく
|
| ユーザー |
koinko_game
|
| 提出日時 | 2019-07-10 23:27:24 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 38 ms / 5,000 ms |
| コード長 | 925 bytes |
| コンパイル時間 | 825 ms |
| コンパイル使用メモリ | 111,872 KB |
| 実行使用メモリ | 28,772 KB |
| 最終ジャッジ日時 | 2024-07-01 09:24:40 |
| 合計ジャッジ時間 | 2,805 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / 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.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;
class Program
{
static int[] dp;
static int N = 0;
static void Main(string[] args)
{
N = int.Parse(ReadLine());
dp = Enumerable.Repeat(1000000000, 10001).ToArray();
dp[1] = 1;
DFS(1);
WriteLine(dp[N] == 1000000000 ? -1 : dp[N]);
}
static void DFS(int from)
{
int delta = 0;
for (int j = 0; j < 32; j++)
if (((from >> j) & 1) == 1)
delta++;
if(N >= from + delta && dp[from + delta] > dp[from] + 1)
{
dp[from + delta] = dp[from] + 1;
DFS(from + delta);
}
if(1 <= from - delta && dp[from - delta] > dp[from] + 1)
{
dp[from - delta] = dp[from] + 1;
DFS(from - delta);
}
}
}
koinko_game