結果
問題 | No.58 イカサマなサイコロ |
ユーザー | 14番 |
提出日時 | 2016-04-06 22:09:30 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 109 ms / 5,000 ms |
コード長 | 4,696 bytes |
コンパイル時間 | 984 ms |
コンパイル使用メモリ | 115,104 KB |
実行使用メモリ | 27,216 KB |
最終ジャッジ日時 | 2024-10-04 02:19:52 |
合計ジャッジ時間 | 1,872 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
24,948 KB |
testcase_01 | AC | 109 ms
27,216 KB |
testcase_02 | AC | 30 ms
24,828 KB |
testcase_03 | AC | 30 ms
22,844 KB |
testcase_04 | AC | 32 ms
26,956 KB |
testcase_05 | AC | 30 ms
24,952 KB |
testcase_06 | AC | 38 ms
23,088 KB |
testcase_07 | AC | 30 ms
27,128 KB |
testcase_08 | AC | 31 ms
25,300 KB |
testcase_09 | AC | 35 ms
24,816 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; public class Program { public void Proc(){ Reader.IsDebug = false; this.DiceCount = int.Parse(Reader.ReadLine()); Dictionary<int, long> jiroDic = this.GetKumiawase(this.DiceCount, 0); int ikasamaCount = int.Parse(Reader.ReadLine()); Dictionary<int,long> taroDic = this.GetKumiawase(this.DiceCount, ikasamaCount); List<int> jiroKeys = new List<int>(); jiroKeys.AddRange(jiroDic.Keys); jiroKeys.Sort(); List<int> taroKeys = new List<int>(); taroKeys.AddRange(taroDic.Keys); taroKeys.Sort(); long winCount = 0; long total = 0; for(int i=0; i<jiroKeys.Count; i++) { total += jiroDic[jiroKeys[i]]; for(int j=0; j<taroKeys.Count; j++) { if(jiroKeys[i] < taroKeys[j]) { winCount += (jiroDic[jiroKeys[i]] * taroDic[taroKeys[j]]); } } } total = total * total; bool mustExit = true; do { mustExit = true; for(long i=2; i<=Math.Sqrt(winCount); i++) { if(winCount % i == 0 && total % i ==0) { winCount = winCount / i; total = total / i; mustExit = false; break; } } } while (!mustExit); Console.WriteLine((winCount / (double)total).ToString("########################0.#######")); } private int DiceCount; private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int,Dictionary<int,long>>(); private Dictionary<int, Dictionary<int, long>> ikasamaDic = new Dictionary<int, Dictionary<int, long>>(); private Dictionary<int, long> GetKumiawase(int cnt, int ikasama) { if(ikasama > 0) { if(ikasamaDic.ContainsKey(cnt)) { return ikasamaDic[cnt]; } } else { if(dic.ContainsKey(cnt)) { return dic[cnt]; } } if(cnt == 1) { Dictionary<int, long> ret = new Dictionary<int, long>(); if(ikasama > 0) { for(int i=4; i<=6; i++) { ret.Add(i, 2); } ikasamaDic.Add(cnt, ret); } else { for(int i=1; i<=6; i++) { ret.Add(i, 1); } dic.Add(cnt, ret); } return ret; } Dictionary<int, long> ans = new Dictionary<int, long>(); if(ikasama > 0) { for(int i=4; i<= 6; i++) { Dictionary<int, long> ret = this.GetKumiawase(cnt - 1, ikasama - 1); foreach (int key in ret.Keys) { int newKey = key + i; if(ans.ContainsKey(newKey)) { ans[newKey] += ret[key] * 2; } else { ans.Add(newKey, ret[key] * 2); } } } ikasamaDic.Add(cnt, ans); } else { for(int i=1; i<= 6; i++) { Dictionary<int, long> ret = this.GetKumiawase(cnt - 1, ikasama); foreach (int key in ret.Keys) { int newKey = key + i; if(ans.ContainsKey(newKey)) { ans[newKey] += ret[key]; } else { ans.Add(newKey, ret[key]); } } } dic.Add(cnt, ans); } return ans; } 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 = @" 2 2 "; }