Submission #502610


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;

namespace Solver
{
    class Program
    {
        const int M = 1000000007;
        const double eps = 1e-9;
        static Combination cb;
        static void Main()
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            var sc = new Scan();
            cb = new Combination();
            int n, k;
            sc.Multi(out n, out k);
            if (n > 10)
                return;

            if (k == 1)
            {
                sw.WriteLine(0);
                sw.Flush();
                return;
            }
            long ans = 0;
            for (int i = 1; i * k <= n; i++)
            {
                ans += cc(n, k, i) / kaijo(i) * sol(n - k * i, k - 1);
            }
            sw.WriteLine(ans);
            sw.Flush();
        }
        static long sol(int n, int k)
        {
            if (n == 0)
                return 1;

            if (k == 1 || n == 1)
                return 0;
            long ret = 0;
            for (int i = 0; k * i <= n; i++)
            {
                ret += pow(cb.Comb(n, k) * Math.Min(k - 1, 2), i) / kaijo(i) * sol(n - k * i, k - 1);
            }
            return ret;
        }
        static int kaijo(int n)
        {
            if (n == 0)
                return 1;

            return kaijo(n - 1) * n;
        }
        static long cc(int n, int k, int i)
        {
            if (i == 0)
                return 1;

            return cb.Comb(n, k) * Math.Min(k - 1, 2) * cc(n - k, k, i - 1);
        }
        static long pow(long a, long b)
        {
            if (b == 0)
                return 1;
            if (b == 1)
                return a % M;

            long t = pow(a, b / 2);
            if ((b & 1) == 0)
                return t * t % M;
            else
                return t * t % M * a % M;
        }
    }
    class Scan
    {
        public int Int { get { return int.Parse(Console.ReadLine().Trim()); } }
        public long Long { get { return long.Parse(Console.ReadLine().Trim()); } }
        public string Str { get { return Console.ReadLine().Trim(); } }
        public int[] IntArr { get { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); } }
        public int[] IntArrWithSep(char sep) { return Console.ReadLine().Trim().Split(sep).Select(int.Parse).ToArray(); }
        public long[] LongArr { get { return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); } }
        public double[] DoubleArr { get { return Console.ReadLine().Split().Select(double.Parse).ToArray(); } }
        public string[] StrArr { get { return Console.ReadLine().Trim().Split(); } }
        public List<int> IntList { get { return Console.ReadLine().Trim().Split().Select(int.Parse).ToList(); } }
        public List<long> LongList { get { return Console.ReadLine().Trim().Split().Select(long.Parse).ToList(); } }
        public void Multi(out int a, out int b) { var arr = IntArr; a = arr[0]; b = arr[1]; }
        public void Multi(out int a, out int b, out int c) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; }
        public void Multi(out int a, out int b, out int c, out int d) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; d = arr[3]; }
        public void Multi(out int a, out string b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1]; }
        public void Multi(out int a, out int b, out string c) { var arr = StrArr; a = int.Parse(arr[0]); b = int.Parse(arr[1]); c = arr[2]; }
        public void Multi(out int a, out char b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1][0]; }
        public void Multi(out long a, out long b) { var arr = LongArr; a = arr[0]; b = arr[1]; }
        public void Multi(out long a, out int b) { var arr = LongArr; a = arr[0]; b = (int)arr[1]; }
        public void Multi(out string a, out string b) { var arr = StrArr; a = arr[0]; b = arr[1]; }
    }
    class Combination
    {
        public long Comb(int n, int r)
        {
            const int M = 1000000007;
            if (n < 0 || r < 0 || r > n)
                return 0;

            if (n - r < r) r = n - r;
            if (r == 0) return 1;
            if (r == 1) return n;
            int[] numerator = new int[r];
            int[] denominator = new int[r];
            for (int k = 0; k < r; k++)
            {
                numerator[k] = n - r + k + 1;
                denominator[k] = k + 1;
            }
            for (int p = 2; p <= r; p++)
            {
                int pivot = denominator[p - 1];
                if (pivot > 1)
                {
                    int offset = (n - r) % p;
                    for (int k = p - 1; k < r; k += p)
                    {
                        numerator[k - offset] /= pivot;
                        denominator[k] /= pivot;
                    }
                }
            }
            long result = 1;
            for (int k = 0; k < r; k++)
                if (numerator[k] > 1) 
                    result = (result * numerator[k]) % M;

            return result;
        }
        public double BigComb(int n, int r)
        {
            if (n < 0 || r < 0 || r > n)
                return 0;

            if (n - r < r) r = n - r;
            if (r == 0) return 1;
            if (r == 1) return n;
            int[] numerator = new int[r];
            int[] denominator = new int[r];
            for (int k = 0; k < r; k++)
            {
                numerator[k] = n - r + k + 1;
                denominator[k] = k + 1;
            }
            for (int p = 2; p <= r; p++)
            {
                int pivot = denominator[p - 1];
                if (pivot > 1)
                {
                    int offset = (n - r) % p;
                    for (int k = p - 1; k < r; k += p)
                    {
                        numerator[k - offset] /= pivot;
                        denominator[k] /= pivot;
                    }
                }
            }
            double result = 1;
            for (int k = 0; k < r; k++)
                if (numerator[k] > 1)
                    result = result * numerator[k];

            return result;
        }
    }

}

Submission Info

Submission Time
Task J - 指さし
User eigorian
Language C# (Mono 3.2.1.0)
Score 0
Code Size 6506 Byte
Status WA
Exec Time 142 ms
Memory 9760 KiB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 10 0 / 140
Status
AC × 3
WA × 1
AC × 19
WA × 11
AC × 25
WA × 44
Set Name Test Cases
Sample 00_example0.txt, 00_example1.txt, 00_example2.txt, 00_example3.txt
Subtask1 10_rand_small_00.txt, 10_rand_small_01.txt, 10_rand_small_02.txt, 10_rand_small_03.txt, 10_rand_small_04.txt, 10_rand_small_05.txt, 10_rand_small_06.txt, 10_rand_small_07.txt, 10_rand_small_08.txt, 10_rand_small_09.txt, 10_rand_small_10.txt, 10_rand_small_11.txt, 10_rand_small_12.txt, 10_rand_small_13.txt, 10_rand_small_14.txt, 10_rand_small_15.txt, 10_rand_small_16.txt, 10_rand_small_17.txt, 10_rand_small_18.txt, 10_rand_small_19.txt, 10_rand_small_20.txt, 10_rand_small_21.txt, 10_rand_small_22.txt, 10_rand_small_23.txt, 10_rand_small_24.txt, 10_rand_small_25.txt, 10_rand_small_26.txt, 10_rand_small_27.txt, 10_rand_small_28.txt, 10_rand_small_29.txt
All 00_example0.txt, 00_example1.txt, 00_example2.txt, 00_example3.txt, 10_rand_small_00.txt, 10_rand_small_01.txt, 10_rand_small_02.txt, 10_rand_small_03.txt, 10_rand_small_04.txt, 10_rand_small_05.txt, 10_rand_small_06.txt, 10_rand_small_07.txt, 10_rand_small_08.txt, 10_rand_small_09.txt, 10_rand_small_10.txt, 10_rand_small_11.txt, 10_rand_small_12.txt, 10_rand_small_13.txt, 10_rand_small_14.txt, 10_rand_small_15.txt, 10_rand_small_16.txt, 10_rand_small_17.txt, 10_rand_small_18.txt, 10_rand_small_19.txt, 10_rand_small_20.txt, 10_rand_small_21.txt, 10_rand_small_22.txt, 10_rand_small_23.txt, 10_rand_small_24.txt, 10_rand_small_25.txt, 10_rand_small_26.txt, 10_rand_small_27.txt, 10_rand_small_28.txt, 10_rand_small_29.txt, 20_rand_00.txt, 20_rand_01.txt, 20_rand_02.txt, 20_rand_03.txt, 20_rand_04.txt, 20_rand_05.txt, 20_rand_06.txt, 20_rand_07.txt, 20_rand_08.txt, 20_rand_09.txt, 20_rand_10.txt, 20_rand_11.txt, 20_rand_12.txt, 20_rand_13.txt, 20_rand_14.txt, 20_rand_15.txt, 20_rand_16.txt, 20_rand_17.txt, 20_rand_18.txt, 20_rand_19.txt, 30_rand_max_0.txt, 30_rand_max_1.txt, 30_rand_max_2.txt, 30_rand_max_3.txt, 30_rand_max_4.txt, 30_rand_max_5.txt, 30_rand_max_6.txt, 30_rand_max_7.txt, 30_rand_max_8.txt, 30_rand_max_9.txt, 40_hand0.txt, 40_hand1.txt, 40_hand2.txt, 40_hand3.txt, 40_hand4.txt
Case Name Status Exec Time Memory
00_example0.txt AC 139 ms 9736 KiB
00_example1.txt AC 131 ms 9608 KiB
00_example2.txt AC 130 ms 9708 KiB
00_example3.txt WA 124 ms 9612 KiB
10_rand_small_00.txt WA 127 ms 9752 KiB
10_rand_small_01.txt WA 128 ms 9656 KiB
10_rand_small_02.txt WA 129 ms 9720 KiB
10_rand_small_03.txt AC 136 ms 9628 KiB
10_rand_small_04.txt WA 135 ms 9612 KiB
10_rand_small_05.txt AC 132 ms 9756 KiB
10_rand_small_06.txt AC 128 ms 9716 KiB
10_rand_small_07.txt AC 133 ms 9736 KiB
10_rand_small_08.txt WA 125 ms 9756 KiB
10_rand_small_09.txt WA 130 ms 9752 KiB
10_rand_small_10.txt AC 126 ms 9728 KiB
10_rand_small_11.txt AC 126 ms 9624 KiB
10_rand_small_12.txt AC 123 ms 9692 KiB
10_rand_small_13.txt AC 124 ms 9740 KiB
10_rand_small_14.txt AC 126 ms 9752 KiB
10_rand_small_15.txt AC 128 ms 9628 KiB
10_rand_small_16.txt AC 126 ms 9628 KiB
10_rand_small_17.txt WA 129 ms 9740 KiB
10_rand_small_18.txt AC 132 ms 9696 KiB
10_rand_small_19.txt WA 130 ms 9732 KiB
10_rand_small_20.txt AC 124 ms 9712 KiB
10_rand_small_21.txt AC 123 ms 9760 KiB
10_rand_small_22.txt AC 124 ms 9632 KiB
10_rand_small_23.txt WA 127 ms 9656 KiB
10_rand_small_24.txt AC 134 ms 9716 KiB
10_rand_small_25.txt WA 125 ms 9628 KiB
10_rand_small_26.txt WA 128 ms 9600 KiB
10_rand_small_27.txt AC 126 ms 9628 KiB
10_rand_small_28.txt AC 124 ms 9756 KiB
10_rand_small_29.txt AC 130 ms 9668 KiB
20_rand_00.txt AC 139 ms 9600 KiB
20_rand_01.txt WA 142 ms 9584 KiB
20_rand_02.txt WA 120 ms 9616 KiB
20_rand_03.txt WA 122 ms 9612 KiB
20_rand_04.txt WA 121 ms 9616 KiB
20_rand_05.txt WA 122 ms 9612 KiB
20_rand_06.txt WA 121 ms 9716 KiB
20_rand_07.txt WA 124 ms 9616 KiB
20_rand_08.txt WA 121 ms 9616 KiB
20_rand_09.txt WA 127 ms 9616 KiB
20_rand_10.txt WA 119 ms 9660 KiB
20_rand_11.txt WA 120 ms 9620 KiB
20_rand_12.txt WA 126 ms 9584 KiB
20_rand_13.txt WA 127 ms 9608 KiB
20_rand_14.txt WA 124 ms 9588 KiB
20_rand_15.txt WA 121 ms 9588 KiB
20_rand_16.txt WA 120 ms 9716 KiB
20_rand_17.txt WA 118 ms 9664 KiB
20_rand_18.txt WA 122 ms 9716 KiB
20_rand_19.txt WA 125 ms 9668 KiB
30_rand_max_0.txt WA 121 ms 9620 KiB
30_rand_max_1.txt WA 122 ms 9620 KiB
30_rand_max_2.txt WA 120 ms 9612 KiB
30_rand_max_3.txt WA 121 ms 9660 KiB
30_rand_max_4.txt WA 126 ms 9660 KiB
30_rand_max_5.txt WA 122 ms 9660 KiB
30_rand_max_6.txt WA 126 ms 9608 KiB
30_rand_max_7.txt WA 125 ms 9640 KiB
30_rand_max_8.txt WA 135 ms 9612 KiB
30_rand_max_9.txt WA 136 ms 9588 KiB
40_hand0.txt AC 127 ms 9756 KiB
40_hand1.txt AC 128 ms 9756 KiB
40_hand2.txt WA 125 ms 9580 KiB
40_hand3.txt WA 124 ms 9600 KiB
40_hand4.txt WA 124 ms 9616 KiB