結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-29 00:55:02 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,044 bytes |
| コンパイル時間 | 1,226 ms |
| コンパイル使用メモリ | 106,624 KB |
| 実行使用メモリ | 24,288 KB |
| 最終ジャッジ日時 | 2024-10-02 06:55:36 |
| 合計ジャッジ時間 | 2,209 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 5 |
コンパイルメッセージ
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.Text;
public class Program
{
public void Proc(){
Reader.IsDebug = false;
int max = int.Parse(Reader.ReadLine());
this.SetPrimeList(max);
this.SetCanWinDic(max);
bool ans = false;
if(CanWin.ContainsKey(max)) {
ans = this.CanWin[max];
}
Console.WriteLine(ans?"Win":"Lose");
}
private void SetCanWinDic(int max) {
this.CanWin.Add(2, false);
if(max >= 3) {
this.CanWin.Add(3, false);
}
List<int> keyList = new List<int>();
keyList.AddRange(CanWin.Keys);
foreach (int key in keyList)
{
foreach (int prime in this.PrimeList)
{
int newKey = key + prime;
if(newKey <= max) {
if(!CanWin.ContainsKey(newKey)) {
CanWin.Add(newKey, true);
}
} else
{
break;
}
}
}
for(int i=4; i<=max; i++) {
if(!CanWin.ContainsKey(i)) {
for(int j=0; j>=this.NearPrimeIndex[i]; j++) {
int prime = this.PrimeList[j];
if(i - j >= 2 && (!CanWin[i-j])) {
CanWin.Add(i, false);
break;
}
}
if(!CanWin.ContainsKey(i)) {
CanWin.Add(i, true);
}
}
}
}
private Dictionary<int, bool> CanWin = new Dictionary<int, bool>();
private List<int> PrimeList = new List<int>();
private int[] NearPrimeIndex;
private void SetPrimeList(int max) {
bool[] tempList = new bool[max+1];
this.NearPrimeIndex = new int[max + 1];
for(int i=2; i<=max; i++) {
if(!tempList[i]) {
PrimeList.Add(i);
for(int j=1; j<=max / i; j++) {
tempList[j*i] = true;
}
}
this.NearPrimeIndex[i] = this.PrimeList.Count - 1;
}
}
public static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
class Reader
{
public static bool IsDebug = true;
private static System.IO.StringReader sr;
public static string ReadLine() {
if(IsDebug) {
if(sr == null) {
sr = new System.IO.StringReader(initStr.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
public static int[] GetInt(char delimiter = ' ') {
string[] inpt = ReadLine().Split(delimiter);
int[] ret = new int[inpt.Length];
for(int i=0; i<inpt.Length; i++) {
ret[i] = int.Parse(inpt[i]);
}
return ret;
}
private static string initStr = @"
10000
";
}
14番