提出 #7897867


ソースコード 拡げる

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    static int n;
    static int[] a;

    static int[,] dp;

    static int rec(int x, int turn)
    {
	if (dp[x, turn] > 0) return dp[x, turn];

	// 先手は先手勝ち、後手は後手勝ちをめざす
	int win = (turn == 0) ? 1 : 2;
	int lose = (turn == 0) ? 2 : 1;
	int nextTurn = (turn  + 1) & 1;
	
	int i = 0;
	while (i < n && a[i] <= x)
	{
	    if (rec(x - a[i], nextTurn) == win)
		return dp[x, turn] = win;
	    i++;
	}
	
	return dp[x, turn] = lose;
    }
    
    public static void Main()
    {
	var tmp = ReadIntArray();
	n = tmp[0]; int k = tmp[1];
	a = ReadIntArray();
	Array.Sort(a);

	// dp [残りの個数, 0: 先手番 / 1: 後手番]
	//    値: 0 未計算, 1: 先手の勝ち, 2: 後手の勝ち
	dp = new int[k+1, 2];

	WriteLine(rec(k, 0) == 1 ? "First" : "Second");
    }
}

提出情報

提出日時
問題 K - Stones
ユーザ unnohideyuki
言語 C# (Mono 4.6.2.0)
得点 100
コード長 1166 Byte
結果 AC
実行時間 121 ms
メモリ 18388 KiB

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 28
セット名 テストケース
All 0_00, 0_01, 0_02, 0_03, 0_04, 0_05, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21
ケース名 結果 実行時間 メモリ
0_00 AC 26 ms 11348 KiB
0_01 AC 23 ms 11348 KiB
0_02 AC 23 ms 11348 KiB
0_03 AC 23 ms 11348 KiB
0_04 AC 23 ms 11348 KiB
0_05 AC 28 ms 18260 KiB
1_00 AC 23 ms 11348 KiB
1_01 AC 28 ms 18260 KiB
1_02 AC 24 ms 14164 KiB
1_03 AC 121 ms 16212 KiB
1_04 AC 120 ms 18388 KiB
1_05 AC 120 ms 16212 KiB
1_06 AC 80 ms 12372 KiB
1_07 AC 61 ms 14164 KiB
1_08 AC 75 ms 12116 KiB
1_09 AC 79 ms 14164 KiB
1_10 AC 76 ms 12116 KiB
1_11 AC 81 ms 12116 KiB
1_12 AC 77 ms 14164 KiB
1_13 AC 79 ms 12116 KiB
1_14 AC 79 ms 12116 KiB
1_15 AC 83 ms 14292 KiB
1_16 AC 77 ms 16212 KiB
1_17 AC 78 ms 10324 KiB
1_18 AC 77 ms 12628 KiB
1_19 AC 78 ms 12244 KiB
1_20 AC 79 ms 18132 KiB
1_21 AC 80 ms 15188 KiB