結果

問題 No.7 プライムナンバーゲーム
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-07-25 15:06:31
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 272 ms / 5,000 ms
コード長 1,574 bytes
コンパイル時間 9,479 ms
コンパイル使用メモリ 165,088 KB
実行使用メモリ 189,028 KB
最終ジャッジ日時 2024-04-10 07:11:53
合計ジャッジ時間 12,837 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
29,952 KB
testcase_01 AC 51 ms
29,824 KB
testcase_02 AC 265 ms
31,104 KB
testcase_03 AC 67 ms
29,824 KB
testcase_04 AC 55 ms
29,824 KB
testcase_05 AC 55 ms
30,336 KB
testcase_06 AC 118 ms
30,080 KB
testcase_07 AC 97 ms
30,208 KB
testcase_08 AC 73 ms
29,952 KB
testcase_09 AC 156 ms
30,464 KB
testcase_10 AC 51 ms
29,824 KB
testcase_11 AC 98 ms
30,196 KB
testcase_12 AC 215 ms
30,836 KB
testcase_13 AC 223 ms
30,976 KB
testcase_14 AC 272 ms
30,976 KB
testcase_15 AC 258 ms
30,976 KB
testcase_16 AC 242 ms
189,028 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (93 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace yukicoder
{
    public class Program
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var k = Prime(n);
            var winlose = new bool[n + 1];
            winlose[0] = true;
            winlose[1] = true;
            if (n > 2)
            {
                for (var i = 3; i < n + 1; i++)
                {
                    if (k.Any(value => i - value >= 0 && !winlose[i - value]))
                    {
                        winlose[i] = true;
                    }
                }
            }
            if (winlose[n])
            {
                Console.WriteLine("Win");
            }
            else
            {
                Console.WriteLine("Lose");
            }
        }
        static List<int> Prime(int n)
        {
            var isPrime = new bool[n + 1];
            var k = new List<int>();
            for (int i = 2; i <= n; i++)
            {
                isPrime[i] = true;
            }

            for (int i = 2; i * i <= n; i++)
            {
                if (isPrime[i])
                {
                    for (int j = i * i; j <= n; j += i)
                    {
                        isPrime[j] = false;
                    }
                }
            }

            for (int i = 2; i <= n; i++)
            {
                if (isPrime[i])
                {
                    k.Add(i);
                }
            }
            return k;
        }
    }
}
0