結果

問題 No.1267 Stop and Coin Game
ユーザー keymoon
提出日時 2020-10-23 22:27:03
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 1,122 ms
コンパイル使用メモリ 111,444 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-07-21 11:11:41
合計ジャッジ時間 5,286 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nv = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = (int)nv[0];
        var v = nv[1];
        var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        if (a.Sum() <= v)
        {
            Console.WriteLine("Draw");
            return;
        }
        bool[] canWin = new bool[1 << n];
        for (int i = canWin.Length - 1; i >= 0; i--)
        {
            long sum = 0;
            for (int j = 0; j < n; j++)
            {
                if ((i >> j & 1) != 1) continue;
                sum += a[j];
            }
            if (v < sum)
            {
                //この状態で回ってきたら勝てるか:もう相手が溢れさせているので勝ち
                canWin[i] = true;
                continue;
            }
            for (int j = 0; j < n; j++)
            {
                if ((i >> j & 1) == 1) continue;
                canWin[i] |= !canWin[i | (1 << j)];
            }
        }
        Console.WriteLine(canWin[0] ? "First" : "Second");
    }
}
0