結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
AreTrash
|
| 提出日時 | 2016-04-14 06:37:10 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 5,000 ms |
| コード長 | 1,473 bytes |
| コンパイル時間 | 845 ms |
| コンパイル使用メモリ | 113,484 KB |
| 実行使用メモリ | 26,724 KB |
| 最終ジャッジ日時 | 2024-10-01 15:42:53 |
| 合計ジャッジ時間 | 2,080 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
using System.Linq;
namespace No7_1 {
public class Program {
public static void Main(string[] args) {
var n = Read(Convert.ToInt32);
var dp = new bool[n + 1];
var primeList = new List<int>();
var p = n;
if(p > 1) {
var numList = Enumerable.Range(2, p - 1).ToList();
var sqrt = (int)Math.Sqrt(p);
while(numList[0] <= sqrt) {
var prime = numList[0];
primeList.Add(prime);
numList.RemoveAll(value => value % prime == 0);
}
primeList.AddRange(numList);
}
for(var i = 4; i <= n; i++){
foreach(var prime in primeList){
if(prime <= i - 2){
if(!dp[i - prime]){
dp[i] = true;
break;
}
}
}
}
Console.WriteLine(dp[n] ? "Win" : "Lose");
}
public static TOutput Read<TOutput>(Converter<string, TOutput> converter) {
return converter(Console.ReadLine());
}
public static List<TOutput> ReadList<TOutput>(Converter<string, TOutput> converter, char c = ' ') {
return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter);
}
}
}
AreTrash