結果

問題 No.2 素因数ゲーム
ユーザー 14番14番
提出日時 2016-03-30 03:39:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 3,676 bytes
コンパイル時間 3,180 ms
コンパイル使用メモリ 108,880 KB
実行使用メモリ 23,268 KB
最終ジャッジ日時 2023-08-27 04:27:15
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,912 KB
testcase_01 AC 60 ms
22,920 KB
testcase_02 AC 60 ms
23,268 KB
testcase_03 AC 59 ms
21,280 KB
testcase_04 AC 59 ms
20,924 KB
testcase_05 AC 60 ms
18,976 KB
testcase_06 AC 59 ms
23,128 KB
testcase_07 AC 61 ms
21,236 KB
testcase_08 AC 60 ms
22,968 KB
testcase_09 AC 61 ms
21,276 KB
testcase_10 AC 60 ms
22,976 KB
testcase_11 AC 59 ms
19,052 KB
testcase_12 AC 60 ms
21,292 KB
testcase_13 AC 61 ms
21,292 KB
testcase_14 AC 58 ms
21,164 KB
testcase_15 AC 58 ms
22,916 KB
testcase_16 AC 58 ms
20,848 KB
testcase_17 AC 59 ms
21,208 KB
testcase_18 AC 60 ms
21,012 KB
testcase_19 AC 59 ms
20,992 KB
testcase_20 AC 59 ms
21,016 KB
testcase_21 AC 58 ms
22,928 KB
testcase_22 AC 59 ms
20,936 KB
testcase_23 AC 59 ms
20,976 KB
testcase_24 AC 59 ms
22,972 KB
testcase_25 AC 58 ms
20,920 KB
testcase_26 AC 59 ms
21,072 KB
testcase_27 AC 59 ms
21,128 KB
testcase_28 AC 59 ms
20,856 KB
testcase_29 AC 59 ms
23,076 KB
testcase_30 AC 58 ms
20,976 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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




";
}

0