結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
_matumo_
|
| 提出日時 | 2018-06-12 13:40:34 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,259 bytes |
| コンパイル時間 | 2,397 ms |
| コンパイル使用メモリ | 113,808 KB |
| 実行使用メモリ | 27,412 KB |
| 最終ジャッジ日時 | 2024-06-30 13:53:12 |
| 合計ジャッジ時間 | 5,165 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 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;
using System.Text;
namespace YukiCoder
{
class Program
{
static sbyte[] dpN = new sbyte[10001]; // 動的計画法
static List<int> pnR; // 素数
//==========================================================================//
// myWin()
//--------------------------------------------------------------------------//
static int myWin(int N)
{
int n = dpN[N];
if (n != 0) return n;
for (int i = 0; i<pnR.Count(); i++)
{
if (pnR[i] >= N) break;
if ((n = myWin(N - pnR[i])) < 0) return dpN[N] = 1;
}
return dpN[N] = -1;
}
//==========================================================================//
// main()
//--------------------------------------------------------------------------//
static void Main(string[] args)
{
//----------------------------------------------------------------------//
// 数値Nの読み込み
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
var nN = int.Parse(Console.ReadLine());
//----------------------------------------------------------------------//
// 素数の計算
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
int k = 0;
pnR = new List<int>();
var pna = Enumerable.Range(2, nN - 1).ToList();
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
while (k * k < nN)
{
k = pna[0];
pnR.Add(k);
pna.RemoveAll(x => x % k == 0);
}
pnR.AddRange(pna);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
//pnR.ToList().ForEach(x => Console.WriteLine(x));
//----------------------------------------------------------------------//
// 動的計画法の準備
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
for (int i = 0; i < 100; i++) dpN[i] = 1;
List<int> pnX = new List<int> { 2, 3, 11, 12, 27, 36, 37, 51, 57, 87, 93 }; // 負け値
foreach (var n in pnX) dpN[n] = -1;
//----------------------------------------------------------------------//
// 実行と結果表示
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
if (myWin(nN) > 0) Console.WriteLine("WIN");
else Console.WriteLine("LOSE");
//for (int i = 0; i < nN; i++) Console.WriteLine(i + "=" + dpN[i] + " ");
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
Console.ReadLine();
}
}
}
_matumo_