結果
| 問題 |
No.58 イカサマなサイコロ
|
| ユーザー |
14番
|
| 提出日時 | 2016-04-06 22:05:38 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,696 bytes |
| コンパイル時間 | 861 ms |
| コンパイル使用メモリ | 113,336 KB |
| 実行使用メモリ | 25,076 KB |
| 最終ジャッジ日時 | 2024-10-04 02:19:46 |
| 合計ジャッジ時間 | 1,940 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 2 |
コンパイルメッセージ
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 = @"
10
0
";
}
14番