結果
| 問題 | 
                            No.642 Two Operations No.1
                             | 
                    
| コンテスト | |
| ユーザー | 
                             bluemegane
                         | 
                    
| 提出日時 | 2018-09-09 11:03:00 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 28 ms / 2,000 ms | 
| コード長 | 926 bytes | 
| コンパイル時間 | 2,032 ms | 
| コンパイル使用メモリ | 104,064 KB | 
| 実行使用メモリ | 19,968 KB | 
| 最終ジャッジ日時 | 2024-12-23 02:45:35 | 
| 合計ジャッジ時間 | 3,109 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Collections.Generic;
using System;
public class P
{
    public int a { get; set; }
    public int times { get; set; }
}
public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ans = getA(n);
        Console.WriteLine(ans);
    }
    public static int getA(int n)
    {
        var hs = new HashSet<int>();
        var q = new Queue<P>();
        q.Enqueue(new P { a = n, times = 0 });
        while (true)
        {
            var w = q.Dequeue();
            if (w.a == 1) return w.times;
            if (w.a % 2 == 0)
            {
                if (hs.Add(w.a / 2)) q.Enqueue(new P { a = w.a / 2, times = w.times + 1 });
                if (hs.Add(w.a + 1)) q.Enqueue(new P { a = w.a + 1, times = w.times + 1 });
            }
            else if (hs.Add(w.a + 1)) q.Enqueue(new P { a = w.a + 1, times = w.times + 1 });
        }
    }
}
            
            
            
        
            
bluemegane