結果
問題 | No.58 イカサマなサイコロ |
ユーザー | 明智重蔵 |
提出日時 | 2015-08-03 21:39:10 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 70 ms / 5,000 ms |
コード長 | 2,818 bytes |
コンパイル時間 | 2,302 ms |
コンパイル使用メモリ | 106,180 KB |
実行使用メモリ | 23,792 KB |
最終ジャッジ日時 | 2023-09-25 00:56:21 |
合計ジャッジ時間 | 3,810 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
21,524 KB |
testcase_01 | AC | 69 ms
23,696 KB |
testcase_02 | AC | 69 ms
23,792 KB |
testcase_03 | AC | 68 ms
21,576 KB |
testcase_04 | AC | 69 ms
23,568 KB |
testcase_05 | AC | 69 ms
19,600 KB |
testcase_06 | AC | 70 ms
21,704 KB |
testcase_07 | AC | 68 ms
19,540 KB |
testcase_08 | AC | 69 ms
21,640 KB |
testcase_09 | AC | 69 ms
23,560 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.Linq; class Program { static string InputPattern = "Input3"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("2"); WillReturn.Add("1"); //出力 //0.62191 //太郎君は普通のサイコロとイカサマなサイコロを1個づつ使用し、 //二郎君は普通のサイコロを2個使用します } else if (InputPattern == "Input2") { WillReturn.Add("10"); WillReturn.Add("0"); //出力 //0.47409 //太郎君はイカサマなサイコロを使わず、公平に勝負しました } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int N = int.Parse(InputList[0]); int K = int.Parse(InputList[1]); Dictionary<int, int> CntDict1 = DeriveCntDict(N, K); Dictionary<int, int> CntDict2 = DeriveCntDict(N, 0); //積の法則で分母を求める Decimal Bunbo = (Decimal)CntDict1.Values.Sum() * (Decimal)CntDict2.Values.Sum(); //積の法則で分子を求める Decimal Bunsi = 0; foreach (var EachPair1 in CntDict1) { foreach (var EachPair2 in CntDict2) { if (EachPair1.Key <= EachPair2.Key) continue; Bunsi += (Decimal)EachPair1.Value * (Decimal)EachPair2.Value; } } Console.WriteLine(Bunsi / Bunbo); } //合計ごとの場合の数を動的計画法で求める static Dictionary<int, int> DeriveCntDict(int pN, int pK) { var CntDict = new Dictionary<int, int>(); CntDict[0] = 1; //初期設定 for (int I = 1; I <= pN; I++) { var NewCntDict = new Dictionary<int, int>(); int[] DiceValsArr = { 1, 2, 3, 4, 5, 6 }; //456サイの場合 if (I <= pK) DiceValsArr = new int[] { 4, 5, 6, 4, 5, 6 }; foreach (int EachDiceVal in DiceValsArr) { foreach (var EachPair in CntDict) { int NewKey = EachPair.Key + EachDiceVal; if (NewCntDict.ContainsKey(NewKey)) { NewCntDict[NewKey] += EachPair.Value; } else NewCntDict[NewKey] = EachPair.Value; } } CntDict = NewCntDict; } return CntDict; } }