結果

問題 No.1683 Robot Guidance
ユーザー 👑 kakel-sankakel-san
提出日時 2024-01-03 00:17:37
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 3,650 bytes
コンパイル時間 14,042 ms
コンパイル使用メモリ 158,464 KB
実行使用メモリ 179,752 KB
最終ジャッジ日時 2024-01-03 00:17:59
合計ジャッジ時間 13,465 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
32,548 KB
testcase_01 AC 76 ms
32,548 KB
testcase_02 AC 76 ms
32,548 KB
testcase_03 AC 120 ms
37,164 KB
testcase_04 AC 83 ms
33,572 KB
testcase_05 AC 94 ms
34,468 KB
testcase_06 AC 124 ms
37,932 KB
testcase_07 AC 111 ms
37,420 KB
testcase_08 AC 232 ms
46,692 KB
testcase_09 AC 107 ms
36,260 KB
testcase_10 AC 165 ms
41,100 KB
testcase_11 AC 162 ms
38,316 KB
testcase_12 AC 210 ms
42,380 KB
testcase_13 AC 115 ms
41,028 KB
testcase_14 AC 209 ms
47,352 KB
testcase_15 AC 125 ms
41,468 KB
testcase_16 AC 121 ms
42,168 KB
testcase_17 AC 98 ms
37,164 KB
testcase_18 AC 104 ms
38,700 KB
testcase_19 AC 77 ms
32,676 KB
testcase_20 AC 89 ms
32,676 KB
testcase_21 AC 77 ms
32,548 KB
testcase_22 AC 113 ms
40,932 KB
testcase_23 AC 116 ms
40,932 KB
testcase_24 AC 255 ms
48,756 KB
testcase_25 AC 117 ms
40,932 KB
testcase_26 AC 149 ms
48,756 KB
testcase_27 AC 151 ms
48,756 KB
testcase_28 AC 120 ms
40,932 KB
testcase_29 AC 115 ms
40,932 KB
testcase_30 AC 116 ms
40,932 KB
testcase_31 AC 111 ms
39,968 KB
testcase_32 AC 113 ms
39,968 KB
testcase_33 AC 114 ms
38,828 KB
testcase_34 AC 129 ms
38,828 KB
testcase_35 AC 118 ms
40,064 KB
testcase_36 AC 128 ms
40,064 KB
testcase_37 AC 109 ms
38,316 KB
testcase_38 AC 106 ms
38,316 KB
testcase_39 AC 116 ms
40,932 KB
testcase_40 AC 75 ms
179,752 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (110 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (a, b, x, y) = (c[0], c[1], c[2], c[3]);
        WriteLine(Robot(a, b, x, y));
    }
    static long Robot(int a, int b, int x, int y)
    {
        var (r, u, l, d) = ((b + 4) / 4, (b + 3) / 4, (b + 2) / 4, (b + 1) / 4);
        var mod = 1_000_000_007;
        var ncr = new NCR(a + b, mod);
        var ans = 0L;
        for (var v = 0; v <= a; ++v)
        {
            var h = a - v;
            if (v < Math.Abs(x)) continue;
            if (h < Math.Abs(y)) continue;
            if ((v - x) % 2 != 0) continue;
            if ((h - y) % 2 != 0) continue;
            var sub = 1L;
            var mr = v - (v - x) / 2;
            var ml = (v - x) / 2;
            var mu = h - (h - y) / 2;
            var md = (h - y) / 2;
            sub = sub * ncr.Calc(mr + r - 1, r - 1) % mod;
            if (ml > 0)
            {
                if (l == 0) continue;
                sub = sub * ncr.Calc(ml + l - 1, l - 1) % mod;
            }
            if (mu > 0)
            {
                if (u == 0) continue;
                sub = sub * ncr.Calc(mu + u - 1, u - 1) % mod;
            }
            if (md > 0)
            {
                if (d == 0) continue;
                sub = sub * ncr.Calc(md + d - 1, d - 1) % mod;
            }
            ans = (ans + sub) % mod;
        }
        return ans;
    }
    class NCR
    {
        int[] facts;
        int[] revFacts;
        int mod;
        public NCR(int n, int mod)
        {
            facts = new int[n + 1];
            revFacts = new int[n + 1];
            this.mod = mod;
            facts[0] = 1;
            var tmp = 1L;
            for (var i = 1; i <= n; ++i)
            {
                tmp = tmp * i % mod;
                facts[i] = (int)tmp;
            }
            tmp = Exp(facts[n], mod - 2);
            revFacts[n] = (int)tmp;
            for (var i = n; i > 1; --i)
            {
                tmp = tmp * i % mod;
                revFacts[i - 1] = (int)tmp;
            }
            revFacts[0] = 1;
        }
        public long Exp(long n, long k)
        {
            n = n % mod;
            if (k == 0) return 1;
            if (k == 1) return n;
            var half = Exp(n, k / 2);
            var result = half * half % mod;
            return ((k % 2) == 0) ? result : (result * n % mod);
        }
        public long Calc(int n, int r)
        {
            return (long)facts[n] * revFacts[r] % mod * revFacts[n - r] % mod;
        }
        /// <summary>nが大きくrが小さい場合の計算</summary>
        public long Calc2(int n, int r)
        {
            var tmp = 1L;
            for (var i = 0; i < r; ++i)
            {
                tmp = tmp * (n - i) % mod;
            }
            return tmp * revFacts[r] % mod;
        }
        public long NPR(int n, int r)
        {
            return (long)facts[n] * revFacts[r] % mod;
        }
        public long Fact(int n)
        {
            return facts[n];
        }
        public long RevFact(int n)
        {
            return revFacts[n];
        }
        public long Inverse(int n)
        {
            return (long)revFacts[n] * facts[n - 1] % mod;
        }
    }
}
0