結果

問題 No.2299 Antitypoglycemia
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-27 08:46:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,597 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 113,520 KB
実行使用メモリ 28,056 KB
最終ジャッジ日時 2024-04-14 21:34:20
合計ジャッジ時間 2,976 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,952 KB
testcase_01 AC 28 ms
27,016 KB
testcase_02 AC 28 ms
25,264 KB
testcase_03 AC 33 ms
27,152 KB
testcase_04 AC 34 ms
27,308 KB
testcase_05 AC 31 ms
24,932 KB
testcase_06 AC 33 ms
25,124 KB
testcase_07 AC 29 ms
25,076 KB
testcase_08 AC 32 ms
25,248 KB
testcase_09 AC 33 ms
25,644 KB
testcase_10 AC 29 ms
22,896 KB
testcase_11 AC 31 ms
25,184 KB
testcase_12 AC 33 ms
25,376 KB
testcase_13 AC 36 ms
25,632 KB
testcase_14 AC 29 ms
25,000 KB
testcase_15 AC 29 ms
25,224 KB
testcase_16 AC 30 ms
25,056 KB
testcase_17 AC 30 ms
26,984 KB
testcase_18 AC 35 ms
23,740 KB
testcase_19 AC 36 ms
27,704 KB
testcase_20 AC 35 ms
25,760 KB
testcase_21 AC 37 ms
28,056 KB
testcase_22 AC 35 ms
25,908 KB
testcase_23 AC 27 ms
25,116 KB
testcase_24 AC 28 ms
25,348 KB
testcase_25 AC 28 ms
25,120 KB
testcase_26 AC 28 ms
27,288 KB
testcase_27 AC 27 ms
25,012 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 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 (n, a, b) = (c[0], c[1], c[2]);
        var mod = 998_244_353;
        var ncr = new NCR(n, mod);
        var ans = 0L;
        if (a == b)
        {
            ans = (ncr.Fact(n) + mod * 2 - ncr.Fact(n - 1) - ncr.Fact(n - 1)) % mod;
        }
        else
        {
            ans = (ncr.Fact(n) + mod * 2 - ncr.Fact(n - 1) - ncr.Fact(n - 1) + ncr.Fact(n - 2)) % mod;
        }
        WriteLine(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];
        }
    }
}
0