結果

問題 No.7 プライムナンバーゲーム
ユーザー iwkjoseciwkjosec
提出日時 2019-10-07 11:39:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 464 ms / 5,000 ms
コード長 1,239 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 111,196 KB
実行使用メモリ 31,644 KB
最終ジャッジ日時 2024-04-09 04:42:39
合計ジャッジ時間 5,863 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
27,520 KB
testcase_01 AC 28 ms
27,204 KB
testcase_02 AC 464 ms
29,348 KB
testcase_03 AC 57 ms
25,432 KB
testcase_04 AC 37 ms
27,208 KB
testcase_05 AC 36 ms
25,360 KB
testcase_06 AC 159 ms
27,240 KB
testcase_07 AC 116 ms
27,476 KB
testcase_08 AC 68 ms
25,300 KB
testcase_09 AC 225 ms
27,120 KB
testcase_10 AC 28 ms
25,160 KB
testcase_11 AC 118 ms
29,280 KB
testcase_12 AC 342 ms
29,072 KB
testcase_13 AC 363 ms
31,636 KB
testcase_14 AC 463 ms
31,644 KB
testcase_15 AC 441 ms
31,392 KB
testcase_16 AC 415 ms
29,332 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var p = new bool[N + 1];
        for (int i = 0; i < p.Length; i++)
        {
            p[i] = IsPrime(i);
        }
        var dp = new int[N + 1];
        for (int i = 4; i < dp.Length; i++)
        {
            var l = new SortedSet<int>();
            for (int j = 2; j < i-1; j++)
            {
                if (p[j])
                {
                    l.Add(dp[i - j]);
                }
            }
            var c = 0;
            foreach (var a in l)
            {
                if (a != c)
                {
                    dp[i] = c;
                    break;
                }
                c++;
            }
            if (c == l.Count) dp[i] = c;
        }
        WriteLine(dp[N] == 0 ? "Lose" : "Win");
    }

    static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;
        for (int i = 2; i * i <= n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
}
0