結果

問題 No.2806 Cornflake Man
ユーザー tobisatis
提出日時 2024-07-12 21:32:41
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 777 ms / 2,000 ms
コード長 2,475 bytes
コンパイル時間 8,268 ms
コンパイル使用メモリ 171,872 KB
実行使用メモリ 189,152 KB
最終ジャッジ日時 2024-07-17 20:26:01
合計ジャッジ時間 14,325 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (100 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
/home/judge/data/code/Main.cs(21,13): warning CS0219: 変数 'max' は割り当てられていますが、その値は使用されていません [/home/judge/data/code/main.csproj]
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

namespace AtCoder;

#nullable enable

using System.Numerics;

static class Extensions
{
    public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}

class AtCoder
{
    object? Solve()
    {
        var n = Int();
        var m = Int();
        var b = new List<int>();
        var o = new HashSet<int>();
        var q = new PriorityQueue<(int, int), (int, int)>();
        var max = int.MaxValue;
        var c = new HashSet<int>();
        Int();
        for (var i = 1; i < n; i++)
        {
            var a = Int();
            q.Enqueue((a, 0), (a, 0));
        }
        while (q.Count > 0)
        {
            var (v, k) = q.Dequeue();
            if (k == 0)
            {
                o.Add(v);
                if (c.Contains(v)) continue;
                b.Add(v);
                c.Add(v);
                var v2 = v * 2;
                if (v2 > m) continue;
                c.Add(v2);
                q.Enqueue((v2, v), (v2, v));
            }
            else
            {
                if (!o.Contains(v)) return -1;
                var v2 = v + k;
                if (v2 > m) continue;
                c.Add(v2);
                q.Enqueue((v2, k), (v2, k));
            }
        }
        Out(b.Count);
        Out(b, " ");
        return null;
    }

    public static void Main() => new AtCoder().Run();
    public void Run()
    {
        var res = Solve();
        if (res != null)
        {
            if (res is bool yes) res = yes ? "Yes" : "No";
            sw.WriteLine(res);
        }
        sw.Flush();
    }

    string[] input = Array.Empty<string>();
    int iter = 0;
    readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };

    string String()
    {
        while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
        return input[iter++];
    }
    T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
    int Int() => Input<int>();
    void Out(object? x, string? separator = null)
    {
        separator ??= Environment.NewLine;
        if (x is System.Collections.IEnumerable obj and not string)
        {
            var firstLine = true;
            foreach (var item in obj)
            {
                if (!firstLine) sw.Write(separator);
                firstLine = false;
                sw.Write(item);
            }
        }
        else sw.Write(x);
        sw.WriteLine();
    }
}
0