結果

問題 No.7 プライムナンバーゲーム
ユーザー nuwasoginuwasogi
提出日時 2015-11-29 16:56:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 2,097 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 116,152 KB
実行使用メモリ 26,700 KB
最終ジャッジ日時 2024-04-09 03:52:46
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,140 KB
testcase_01 AC 29 ms
22,832 KB
testcase_02 AC 89 ms
25,064 KB
testcase_03 AC 34 ms
26,700 KB
testcase_04 AC 30 ms
25,048 KB
testcase_05 AC 31 ms
24,928 KB
testcase_06 AC 47 ms
24,796 KB
testcase_07 AC 42 ms
24,880 KB
testcase_08 AC 34 ms
22,964 KB
testcase_09 AC 56 ms
24,772 KB
testcase_10 AC 28 ms
24,792 KB
testcase_11 AC 41 ms
22,836 KB
testcase_12 AC 72 ms
25,136 KB
testcase_13 AC 74 ms
24,796 KB
testcase_14 AC 89 ms
24,756 KB
testcase_15 AC 87 ms
24,932 KB
testcase_16 AC 81 ms
25,056 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.Linq;

namespace PrimeNumberGame_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver sol = new Solver();
            Console.WriteLine(sol.Solve() ? "Win" : "Lose");
        }
    }

    class Solver
    {
        int[] PrimeNumber;
        int N;
        bool[] WL;

        public bool Solve()
        {
            if (N <= 3) return false;
            PrimeNumber = SieveOfEratosthenes(N - 2);
            for (int i = 4; i <= N; i++)
            {
                WL[i] = PrimeNumber.Any(n => (n <= i - 2) && !WL[i - n]);
            }
            return WL[N];
        }

        public Solver()
        {
            N = ri();
            WL = new bool[N + 1];
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa() { return Console.ReadLine().Split(' '); }
        static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }

        /* max以下の素数の配列を返す (max は1以上)*/
        public int[] SieveOfEratosthenes(int max)
        {
            bool[] is_prime = new bool[max + 1];
            int cur;
            for (int i = 2; i < is_prime.Length; i++)
            {
                is_prime[i] = true;
            }
            for (cur = 2; cur < is_prime.Length; cur++)
            {
                if (!is_prime[cur]) continue;
                for (int nc = cur * 2; nc <= max; nc += cur)
                {
                    is_prime[nc] = false;
                }
            }
            return Enumerable.Range(2, max - 1).Where(e => is_prime[e]).ToArray();
        }
    }
}
0