結果

問題 No.1741 Arrays and XOR Procedure
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-29 13:58:17
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 3,467 bytes
コンパイル時間 7,961 ms
コンパイル使用メモリ 158,500 KB
実行使用メモリ 180,064 KB
最終ジャッジ日時 2023-12-29 13:58:35
合計ジャッジ時間 16,675 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
32,676 KB
testcase_01 AC 85 ms
32,676 KB
testcase_02 AC 79 ms
32,676 KB
testcase_03 AC 190 ms
46,628 KB
testcase_04 AC 77 ms
32,676 KB
testcase_05 AC 161 ms
47,472 KB
testcase_06 AC 171 ms
48,644 KB
testcase_07 AC 170 ms
48,644 KB
testcase_08 AC 163 ms
47,472 KB
testcase_09 AC 168 ms
46,792 KB
testcase_10 AC 194 ms
47,076 KB
testcase_11 AC 149 ms
44,600 KB
testcase_12 AC 134 ms
40,100 KB
testcase_13 AC 155 ms
46,392 KB
testcase_14 AC 131 ms
40,740 KB
testcase_15 AC 153 ms
45,844 KB
testcase_16 AC 90 ms
33,444 KB
testcase_17 AC 111 ms
36,772 KB
testcase_18 AC 178 ms
41,124 KB
testcase_19 AC 83 ms
33,316 KB
testcase_20 AC 171 ms
48,016 KB
testcase_21 AC 160 ms
45,220 KB
testcase_22 AC 138 ms
44,444 KB
testcase_23 AC 101 ms
36,516 KB
testcase_24 AC 94 ms
33,956 KB
testcase_25 AC 163 ms
47,796 KB
testcase_26 AC 112 ms
38,308 KB
testcase_27 AC 81 ms
33,316 KB
testcase_28 AC 142 ms
44,920 KB
testcase_29 AC 152 ms
46,108 KB
testcase_30 AC 151 ms
44,804 KB
testcase_31 AC 84 ms
33,444 KB
testcase_32 AC 113 ms
38,308 KB
testcase_33 AC 126 ms
39,460 KB
testcase_34 AC 95 ms
35,492 KB
testcase_35 AC 79 ms
32,932 KB
testcase_36 AC 87 ms
34,212 KB
testcase_37 AC 111 ms
38,052 KB
testcase_38 AC 171 ms
47,620 KB
testcase_39 AC 107 ms
37,284 KB
testcase_40 AC 79 ms
32,932 KB
testcase_41 AC 93 ms
35,108 KB
testcase_42 AC 83 ms
33,316 KB
testcase_43 AC 87 ms
180,064 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (121 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 n = NN;
        var b = NList;
        var ncr = new NCR(n - 1, 2);
        var dp0 = 1L;
        var dp1 = 0L;
        var mod = 998_244_353;
        for (var i = 0; i < b.Length; ++i)
        {
            var ev = NcrIsEven(n - 1, i);
            var ndp0 = 0L;
            var ndp1 = 0L;
            if (b[i] != 1)
            {
                ndp0 = (ndp0 + dp0) % mod;
                ndp1 = (ndp1 + dp1) % mod;
            }
            if (b[i] != 0)
            {
                if (ev)
                {
                    ndp0 = (ndp0 + dp0) % mod;
                    ndp1 = (ndp1 + dp1) % mod;
                }
                else
                {
                    ndp0 = (ndp0 + dp1) % mod;
                    ndp1 = (ndp1 + dp0) % mod;
                }
            }
            dp0 = ndp0;
            dp1 = ndp1;
        }
        WriteLine(dp1);
    }
    static bool NcrIsEven(int n, int r)
    {
        return DCount(n) - DCount(r) - DCount(n - r) > 0;
    }
    static int DCount(int n)
    {
        var ans = 0;
        for (var i = 2; i <= n; i <<= 1)
        {
            ans += n / i;
        }
        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