Submission #5392766


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];

            var pattern = new Dictionary<int, double>
            {
                { 2, N * 4 },
                { 3, N * 2 },
                { 5, N * 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, 2 * N + 1, N + 1, N + 1];
            dp[0, 0, 0, 0] = 1;
            for (int i = 1; i <= N; i++)
            {
                for (int b = 0; b <= N; b++)
                    for (int c = 0; c <= N; c++)
                        for (int a = 0; a <= 2 * N; a++)
                        {
                            double tmp = dp[i - 1, a, b, c];
                            if (a >= 1)
                            {
                                tmp += dp[i - 1, a - 1, b, c];
                                if (a >= 2)
                                    tmp += dp[i - 1, a - 2, b, c];
                                if (b >= 1)
                                    tmp += dp[i - 1, a - 1, b - 1, c];
                            }
                            if (b >= 1)
                                tmp += dp[i - 1, a, b - 1, c];
                            if (c >= 1)
                                tmp += dp[i - 1, a, b, c - 1];
                            dp[i, a, b, c] = tmp / 6.0;
                        }
            }

            double sum = 0;
            for (int a = twoCount; a <= 2 * N; a++)
                for (int b = threeCount; b <= N; b++)
                    for (int c = fiveCount; c <= N; c++)
                        sum += dp[N, a, b, c];

            return sum;
        }

        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 0
Code Size 4404 Byte
Status TLE
Exec Time 2108 ms
Memory 238176 KB

Judge Result

Set Name All
Score / Max Score 0 / 4
Status
AC × 7
TLE × 6
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 181 ms 26848 KB
01 TLE 2108 ms 227936 KB
02 TLE 2108 ms 234080 KB
03 AC 270 ms 39904 KB
04 AC 245 ms 36448 KB
05 TLE 2108 ms 213600 KB
06 TLE 2108 ms 219744 KB
07 TLE 2108 ms 223840 KB
08 AC 38 ms 12768 KB
09 TLE 2108 ms 238176 KB
10 AC 25 ms 9184 KB
90 AC 25 ms 11232 KB
91 AC 26 ms 11232 KB