結果

問題 No.212 素数サイコロと合成数サイコロ (2)
ユーザー 14番14番
提出日時 2016-05-03 23:27:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 3,865 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 113,156 KB
実行使用メモリ 34,164 KB
最終ジャッジ日時 2024-04-15 11:07:58
合計ジャッジ時間 2,433 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
25,496 KB
testcase_01 AC 42 ms
25,772 KB
testcase_02 AC 43 ms
25,368 KB
testcase_03 AC 45 ms
27,816 KB
testcase_04 AC 53 ms
29,184 KB
testcase_05 AC 79 ms
34,164 KB
testcase_06 AC 62 ms
31,528 KB
testcase_07 AC 63 ms
29,816 KB
testcase_08 AC 46 ms
27,636 KB
testcase_09 AC 42 ms
25,648 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;
using System.Linq;
 
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.GetInt();
        Dictionary<ulong, ulong> kumi = this.GetKumiawase(inpt[0], inpt[1]);
        ulong total = 0;
        decimal caseCount = 0;
        kumi.ToList().ForEach((a)=>{
            caseCount+=a.Value;
            total+=(a.Key * a.Value);
        });
        decimal ans = total / caseCount;
        Console.WriteLine(ans.ToString("#0.################################0"));
    }
    
    private Dictionary<int, Dictionary<int, Dictionary<ulong, ulong>>> dic = new Dictionary<int, Dictionary<int, Dictionary<ulong, ulong>>>();
    
    private Dictionary<ulong, ulong> GetKumiawase(int sosuDiceCount, int gouseiDiceCount) {
        if(!dic.ContainsKey(sosuDiceCount)) {
            dic.Add(sosuDiceCount, new Dictionary<int, Dictionary<ulong, ulong>>());
        }
        if(dic[sosuDiceCount].ContainsKey(gouseiDiceCount)) {
            return dic[sosuDiceCount][gouseiDiceCount];
        }
        
        Dictionary<ulong, ulong> ans = new Dictionary<ulong, ulong>();
        if(sosuDiceCount == 1 && gouseiDiceCount == 0) {
            SosuDice.ToList().ForEach(a=>ans.Add((ulong)a, 1));
        } else if(gouseiDiceCount == 1 && sosuDiceCount == 0) {
            GouseiDice.ToList().ForEach(a=> ans.Add((ulong)a, 1));
        } else
        {
            if(sosuDiceCount > 0) {
                Dictionary<ulong, ulong> ret = this.GetKumiawase(sosuDiceCount - 1, gouseiDiceCount);
                this.SosuDice.ToList().ForEach(a=> ret.ToList().ForEach((b)=>{
                    ulong newKey = (ulong)a * b.Key;
                    if(ans.ContainsKey(newKey)) {
                        ans[newKey]+=b.Value;
                    } else
                    {
                        ans.Add(newKey, b.Value);
                    }
                }));
            }
            if(gouseiDiceCount > 0) {
                Dictionary<ulong, ulong> ret = this.GetKumiawase(sosuDiceCount, gouseiDiceCount - 1);
                this.GouseiDice.ToList().ForEach(a=> ret.ToList().ForEach((b)=>{
                    ulong newKey = (ulong)a * b.Key;
                    if(ans.ContainsKey(newKey)) {
                        ans[newKey]+=b.Value;
                    } else
                    {
                        ans.Add(newKey, b.Value);
                    }
                }));
            }
        }
        this.dic[sosuDiceCount].Add(gouseiDiceCount, ans);
        return ans;
    }

    
    private int[] SosuDice = new int[]{2,3,5,7,11,13};
    private int[] GouseiDice = new int[]{4,6,8,9,10,12};
    
    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"



3 4



 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0