結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
mori_chibi
|
| 提出日時 | 2017-08-29 14:56:56 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 5,000 ms |
| コード長 | 1,469 bytes |
| コンパイル時間 | 950 ms |
| コンパイル使用メモリ | 105,856 KB |
| 実行使用メモリ | 17,920 KB |
| 最終ジャッジ日時 | 2024-10-01 16:06:58 |
| 合計ジャッジ時間 | 2,088 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
namespace PrimeGame
{
class Program
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
string R = MainProcess(N);
Console.WriteLine(R);
}
private static string MainProcess(int n)
{
const string win = "Win";
const string los = "Lose";
List<int> P = PrimeProcess(n);
bool[] ary = new bool[n + 1];
ary[0] = true;
ary[1] = true;
for (int i = 2; i <= n; i++)
{
for (int j = 0; (!ary[i]) && j < P.Count && i >= P[j]; j++)
{
ary[i] |= !ary[i - P[j]];
}
}
return (ary[n]) ? win : los;
}
private static List<int> PrimeProcess(int n)
{
List<int> prime = new List<int>(n/2);
prime.Add(2);
for (int i = 3; i < n; i += 2)
{
double sq = Math.Sqrt(i);
foreach (int p in prime)
{
if (sq < p)
{
prime.Add(i);
break;
}
else if (i % p == 0)
{
break;
}
}
}
return prime;
}
}
}
mori_chibi