結果
問題 | No.212 素数サイコロと合成数サイコロ (2) |
ユーザー | 14番 |
提出日時 | 2016-05-03 23:27:19 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 68 ms / 5,000 ms |
コード長 | 3,865 bytes |
コンパイル時間 | 828 ms |
コンパイル使用メモリ | 116,704 KB |
実行使用メモリ | 36,400 KB |
最終ジャッジ日時 | 2024-10-05 06:07:55 |
合計ジャッジ時間 | 1,857 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
25,772 KB |
testcase_01 | AC | 33 ms
25,080 KB |
testcase_02 | AC | 33 ms
25,596 KB |
testcase_03 | AC | 34 ms
25,380 KB |
testcase_04 | AC | 42 ms
27,440 KB |
testcase_05 | AC | 68 ms
36,400 KB |
testcase_06 | AC | 50 ms
31,404 KB |
testcase_07 | AC | 52 ms
29,820 KB |
testcase_08 | AC | 34 ms
23,092 KB |
testcase_09 | AC | 35 ms
28,140 KB |
コンパイルメッセージ
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; 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(); } }