Submission #5401855
Source Code Expand
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
namespace AtCoderProject
{
public class Program
{
public object Calc()
{
var line = consoleReader.SplitLong();
var N = (int)line[0];
var D = line[1];
long amari;
int twoCount, threeCount, fiveCount;
long num = D;
for (twoCount = 0; ; twoCount++)
{
var d = Math.DivRem(num, 2, out amari);
if (amari != 0) break;
num = d;
}
for (threeCount = 0; ; threeCount++)
{
var d = Math.DivRem(num, 3, out amari);
if (amari != 0) break;
num = d;
}
for (fiveCount = 0; ; fiveCount++)
{
var d = Math.DivRem(num, 5, out amari);
if (amari != 0) break;
num = d;
}
if (num != 1)
return 0;
var dp = new double[N + 1, twoCount + 1, threeCount + 1, fiveCount + 1];
dp[0, 0, 0, 0] = 1;
for (int i = 0; i < N; i++)
{
for (int t = 0; t <= twoCount; t++)
for (int th = 0; th <= threeCount; th++)
for (int f = 0; f <= fiveCount; f++)
{
var current = dp[i, t, th, f] / 6;
// 1
dp[i + 1, t, th, f] += current;
// 2
if (t < twoCount)
dp[i + 1, t + 1, th, f] += current;
else
dp[i + 1, twoCount, th, f] += current;
// 3
if (th < threeCount)
dp[i + 1, t, th + 1, f] += current;
else
dp[i + 1, t, threeCount, f] += current;
// 4
if (t < twoCount - 1)
dp[i + 1, t + 2, th, f] += current;
else
dp[i + 1, twoCount, th, f] += current;
// 5
if (f < fiveCount)
dp[i + 1, t, th, f + 1] += current;
else
dp[i + 1, t, th, fiveCount] += current;
// 6
if (t < twoCount && th < threeCount)
dp[i + 1, t + 1, th + 1, f] += current;
else if (t < twoCount)
dp[i + 1, t + 1, threeCount, f] += current;
else if (th < threeCount)
dp[i + 1, twoCount, th + 1, f] += current;
else
dp[i + 1, twoCount, threeCount, f] += current;
}
}
return dp[N, twoCount, threeCount, fiveCount];
}
public const int mod = 1000000007;
#region いつもの
private readonly ConsoleReader consoleReader;
public Program() : this(new ConsoleReader()) { }
public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
static void Main() => Console.WriteLine(new Program().Calc());
public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
#endregion
}
#region Console
public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
#endregion
}
Submission Info
Submission Time |
|
Task |
D - サイコロ |
User |
kzrnm |
Language |
C# (Mono 4.6.2.0) |
Score |
4 |
Code Size |
5069 Byte |
Status |
AC |
Exec Time |
29 ms |
Memory |
13396 KB |
Judge Result
Set Name |
All |
Score / Max Score |
4 / 4 |
Status |
|
Set Name |
Test Cases |
All |
00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 90, 91 |
Case Name |
Status |
Exec Time |
Memory |
00 |
AC |
24 ms |
11192 KB |
01 |
AC |
28 ms |
9568 KB |
02 |
AC |
25 ms |
9224 KB |
03 |
AC |
25 ms |
11232 KB |
04 |
AC |
25 ms |
13284 KB |
05 |
AC |
29 ms |
11744 KB |
06 |
AC |
28 ms |
11488 KB |
07 |
AC |
25 ms |
11360 KB |
08 |
AC |
25 ms |
9184 KB |
09 |
AC |
24 ms |
11292 KB |
10 |
AC |
23 ms |
9300 KB |
90 |
AC |
24 ms |
11348 KB |
91 |
AC |
24 ms |
13396 KB |