結果

問題 No.7 プライムナンバーゲーム
ユーザー HimatsubushinHimatsubushin
提出日時 2021-01-15 09:19:46
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 1,495 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 115,120 KB
実行使用メモリ 26,996 KB
最終ジャッジ日時 2024-04-09 05:02:05
合計ジャッジ時間 2,488 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
26,980 KB
testcase_01 AC 28 ms
26,992 KB
testcase_02 AC 27 ms
25,080 KB
testcase_03 AC 26 ms
24,956 KB
testcase_04 AC 27 ms
26,996 KB
testcase_05 AC 27 ms
24,824 KB
testcase_06 AC 26 ms
26,764 KB
testcase_07 AC 27 ms
26,864 KB
testcase_08 AC 27 ms
25,008 KB
testcase_09 AC 29 ms
25,080 KB
testcase_10 AC 26 ms
25,088 KB
testcase_11 AC 26 ms
25,084 KB
testcase_12 AC 36 ms
25,136 KB
testcase_13 AC 26 ms
24,996 KB
testcase_14 AC 32 ms
26,992 KB
testcase_15 AC 32 ms
26,924 KB
testcase_16 AC 37 ms
24,876 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;

namespace No._07
{
    class Program
    {
        static List<int> prime = new List<int>();
        static bool[,] memo;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            memo = new bool[n + 1, 2];
            memo[0, 0] = memo[0, 1] = true;
            memo[1, 0] = memo[1, 1] = true;

            primeCheck(n);

            if (judgmentCheck(n))
            {
                Console.WriteLine("Win");
            }
            else
            {
                Console.WriteLine("Lose");
            }
        }

        static void primeCheck(int n)
        {
            bool[] data = Enumerable.Repeat(true, n + 1).ToArray();

            for (int i = 4; i <= n; i += 2)
                data[i] = false;

            for (int i = 3; i <= (int)Math.Sqrt((double)n); i += 2)
                for (int j = 2; i * j <= n; j++)
                    data[i * j] = false;

            for (int i = n; i >= 2; i--)
                if (data[i])
                    prime.Add(i);

            return;
        }

        static bool judgmentCheck(int n)
        {
            if (memo[n, 0])
                return memo[n, 1];

            memo[n, 0] = true;

            foreach (int a in prime)
                if (n >= a)
                    if (!judgmentCheck(n - a))
                        return memo[n, 1] = true;

            return false;
        }
    }
}
0