結果
| 問題 | No.2 素因数ゲーム |
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-30 03:39:02 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 5,000 ms |
| コード長 | 3,676 bytes |
| コンパイル時間 | 2,607 ms |
| コンパイル使用メモリ | 106,880 KB |
| 実行使用メモリ | 18,376 KB |
| 最終ジャッジ日時 | 2024-12-26 12:27:02 |
| 合計ジャッジ時間 | 5,045 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
コンパイルメッセージ
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 baseNum = int.Parse(Reader.ReadLine());
this.canWinDic = new Nullable<bool>[baseNum + 1];
Soinsu = this.GetSoinsu(baseNum);
bool ans = this.GetCanWin(baseNum, this.Soinsu);
Console.WriteLine(ans?"Alice":"Bob");
}
public bool GetCanWin(int num, Dictionary<int,int> ele) {
if(this.canWinDic[num] != null) {
return this.canWinDic[num].Value;
}
bool onlyWin = true;
foreach (int key in ele.Keys)
{
if(ele[key] > 0) {
for(int i=1; i<=ele[key]; i++) {
int tmp = (int)Math.Pow(key, i);
Dictionary<int, int> subDic = new Dictionary<int, int>();
foreach (int k in ele.Keys)
{
subDic.Add(k, ele[k]);
}
subDic[key]-=i;
if(subDic[key] <=0) {
subDic.Remove(key);
}
if(this.GetCanWin(num / tmp, subDic)) {
} else {
onlyWin = false;
}
}
}
}
if(onlyWin) {
this.canWinDic[num] = false;
} else {
this.canWinDic[num] = true;
}
return this.canWinDic[num].Value;
}
private Dictionary<int, int> Soinsu;
private Nullable<bool>[] canWinDic;
private void SetBaseDic() {
this.canWinDic[1] = false;
foreach (int key in this.Soinsu.Keys)
{
for(int i=1; i<=this.Soinsu[key]; i++) {
int mul = (int)Math.Pow(key, i);
this.canWinDic[mul] = true;
}
}
}
private Dictionary<int, int> GetSoinsu(int src) {
Dictionary<int, int> ret = new Dictionary<int, int>();
int num = src;
while (num > 1)
{
bool isBreak = false;
for(int i=2; i<=Math.Sqrt(num); i++) {
if(num % i == 0) {
isBreak = true;
if(ret.ContainsKey(i)) {
ret[i]++;
} else
{
ret.Add(i, 1);
}
num = num / i;
break;
}
}
if(isBreak == false) {
break;
}
}
if(num > 1) {
if(ret.ContainsKey(num)) {
ret[num]++;
} else
{
ret.Add(num, 1);
}
}
return ret;
}
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 = @"
24
";
}
14番