結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー AreTrashAreTrash
提出日時 2018-03-15 14:00:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 4,345 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 108,160 KB
実行使用メモリ 46,336 KB
最終ジャッジ日時 2024-05-09 18:27:43
合計ジャッジ時間 9,504 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
19,328 KB
testcase_01 AC 27 ms
18,816 KB
testcase_02 AC 29 ms
19,328 KB
testcase_03 AC 27 ms
19,200 KB
testcase_04 AC 53 ms
23,424 KB
testcase_05 AC 26 ms
19,328 KB
testcase_06 AC 26 ms
19,328 KB
testcase_07 AC 26 ms
19,328 KB
testcase_08 AC 27 ms
18,944 KB
testcase_09 AC 68 ms
26,880 KB
testcase_10 AC 43 ms
21,248 KB
testcase_11 AC 75 ms
27,648 KB
testcase_12 AC 43 ms
21,224 KB
testcase_13 AC 105 ms
34,688 KB
testcase_14 AC 48 ms
22,400 KB
testcase_15 AC 40 ms
20,992 KB
testcase_16 AC 50 ms
22,912 KB
testcase_17 AC 65 ms
25,472 KB
testcase_18 AC 129 ms
41,728 KB
testcase_19 AC 28 ms
18,816 KB
testcase_20 AC 29 ms
19,072 KB
testcase_21 AC 28 ms
19,200 KB
testcase_22 AC 29 ms
19,328 KB
testcase_23 AC 28 ms
19,072 KB
testcase_24 AC 28 ms
18,816 KB
testcase_25 AC 31 ms
19,712 KB
testcase_26 AC 28 ms
19,328 KB
testcase_27 AC 31 ms
19,456 KB
testcase_28 AC 29 ms
18,816 KB
testcase_29 AC 28 ms
19,072 KB
testcase_30 AC 28 ms
19,200 KB
testcase_31 AC 28 ms
19,200 KB
testcase_32 AC 29 ms
18,816 KB
testcase_33 AC 28 ms
19,200 KB
testcase_34 AC 27 ms
18,944 KB
testcase_35 AC 29 ms
19,200 KB
testcase_36 AC 29 ms
19,200 KB
testcase_37 AC 29 ms
19,072 KB
testcase_38 AC 28 ms
18,944 KB
testcase_39 AC 29 ms
18,944 KB
testcase_40 AC 28 ms
18,944 KB
testcase_41 AC 28 ms
19,072 KB
testcase_42 AC 29 ms
19,200 KB
testcase_43 AC 27 ms
19,200 KB
testcase_44 AC 27 ms
19,200 KB
testcase_45 AC 29 ms
19,328 KB
testcase_46 AC 29 ms
19,072 KB
testcase_47 AC 28 ms
19,200 KB
testcase_48 AC 27 ms
19,200 KB
testcase_49 AC 107 ms
37,376 KB
testcase_50 AC 34 ms
20,608 KB
testcase_51 AC 35 ms
20,352 KB
testcase_52 AC 42 ms
23,168 KB
testcase_53 AC 36 ms
21,376 KB
testcase_54 AC 43 ms
23,552 KB
testcase_55 AC 32 ms
19,840 KB
testcase_56 AC 39 ms
20,864 KB
testcase_57 AC 61 ms
26,240 KB
testcase_58 AC 99 ms
35,584 KB
testcase_59 AC 90 ms
32,896 KB
testcase_60 AC 53 ms
23,552 KB
testcase_61 AC 154 ms
46,336 KB
testcase_62 AC 53 ms
23,552 KB
testcase_63 AC 95 ms
35,968 KB
testcase_64 AC 44 ms
23,424 KB
testcase_65 AC 38 ms
21,532 KB
testcase_66 AC 46 ms
23,040 KB
testcase_67 AC 46 ms
23,260 KB
testcase_68 AC 50 ms
23,604 KB
testcase_69 AC 55 ms
23,808 KB
testcase_70 AC 47 ms
22,144 KB
testcase_71 AC 40 ms
20,736 KB
testcase_72 AC 57 ms
25,088 KB
testcase_73 AC 40 ms
21,120 KB
testcase_74 AC 40 ms
20,736 KB
testcase_75 AC 40 ms
20,864 KB
testcase_76 AC 46 ms
22,016 KB
testcase_77 AC 47 ms
22,016 KB
testcase_78 AC 35 ms
19,840 KB
testcase_79 AC 38 ms
20,352 KB
testcase_80 AC 34 ms
19,712 KB
testcase_81 AC 29 ms
19,132 KB
testcase_82 AC 54 ms
24,320 KB
testcase_83 AC 40 ms
21,248 KB
testcase_84 AC 35 ms
19,712 KB
testcase_85 AC 111 ms
25,344 KB
testcase_86 AC 113 ms
24,448 KB
testcase_87 AC 31 ms
19,396 KB
testcase_88 AC 29 ms
18,944 KB
testcase_89 AC 73 ms
27,776 KB
testcase_90 AC 119 ms
40,064 KB
testcase_91 AC 137 ms
42,368 KB
testcase_92 AC 49 ms
22,656 KB
testcase_93 AC 105 ms
38,272 KB
testcase_94 AC 56 ms
23,936 KB
testcase_95 AC 103 ms
36,736 KB
testcase_96 AC 102 ms
34,560 KB
testcase_97 AC 99 ms
33,280 KB
testcase_98 AC 79 ms
29,696 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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

namespace No389_1
{
    public class Program
    {
        void Solve(StreamWriter sw)
        {
            //---------------------------------
            var M = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
            var K = H.Length;

            if (K == 1 && H[0] == 0)
            {
                sw.WriteLine(1);
                return;
            }

            if (M < H.Sum() + K - 1)
            {
                sw.WriteLine("NA");
                return;
            }

            var comb = new Combination(M);
            sw.WriteLine(comb.NCK(M - H.Sum() + 1, K));
            //---------------------------------
        }

        static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(sw);
            sw.Flush();
        }
    }

    public static partial class MathX
    {
        public static int GcdEx(int a, int b, out int x, out int y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }

            int tx, ty;
            var gcd = GcdEx(b, a % b, out tx, out ty);

            x = ty;
            y = tx - ty * (a / b);
            return gcd;
        }
    }

    public struct ModInt
    {
        public static int Mod = 1000000007;

        readonly long value;
        public int Value { get { return (int)value; } }
        public ModInt Inverse { get { return GetInverse(); } }

        public ModInt(long value)
        {
            value %= Mod;
            this.value = value < 0 ? value + Mod : value;
        }

        ModInt GetInverse()
        {
            int x, y;
            if (MathX.GcdEx(Value, Mod, out x, out y) != 1)
            {
                throw new InvalidOperationException("'Value' and 'Mod' must be disjoint.");
            }
            return x;
        }

        public ModInt Square()
        {
            return this * this;
        }

        public ModInt Pow(long exp)
        {
            if (exp == 0) return 1;
            if (exp % 2 == 0) return Pow(exp / 2).Square();
            return this * Pow(exp - 1);
        }

        public static ModInt Parse(string str)
        {
            return long.Parse(str);
        }

        public static implicit operator ModInt(long value)
        {
            return new ModInt(value);
        }

        public static ModInt operator +(ModInt left, ModInt right)
        {
            return left.value + right.value;
        }

        public static ModInt operator -(ModInt left, ModInt right)
        {
            return left.value - right.value;
        }

        public static ModInt operator *(ModInt left, ModInt right)
        {
            return left.value * right.value;
        }

        public static ModInt operator /(ModInt left, ModInt right)
        {
            return left * right.Inverse;
        }

        public override bool Equals(object obj)
        {
            if (!(obj is ModInt)) return false;
            return value == ((ModInt)obj).value;
        }

        public override int GetHashCode()
        {
            return value.GetHashCode();
        }

        public override string ToString()
        {
            return value.ToString();
        }
    }

    public class Combination
    {
        readonly ModInt[] facts;

        public Combination(int max)
        {
            facts = new ModInt[max + 1];
            facts[0] = 1;
            for (var i = 1; i <= max; i++) facts[i] = facts[i - 1] * i;
        }

        public ModInt Fact(int n)
        {
            return facts[n];
        }

        public ModInt NCK(int n, int k)
        {
            if (n < k) return 0;
            return facts[n] / facts[k] / facts[n - k];
        }

        public ModInt NPK(int n, int k)
        {
            if (n < k) return 0;
            return facts[n] / facts[n - k];
        }

        public ModInt NHK(int n, int k)
        {
            if (k == 0) return 1;
            if (n == 0) return 0;
            return facts[n + k - 1] / facts[k] / facts[n - 1];
        }
    }
}
0