結果

問題 No.2 素因数ゲーム
ユーザー 14番14番
提出日時 2016-03-30 03:38:09
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,662 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 114,648 KB
実行使用メモリ 28,668 KB
最終ジャッジ日時 2024-04-10 01:51:08
合計ジャッジ時間 2,981 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
    }
    
    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