結果
問題 | No.1741 Arrays and XOR Procedure |
ユーザー |
|
提出日時 | 2023-12-29 13:58:17 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 131 ms / 2,000 ms |
コード長 | 3,467 bytes |
コンパイル時間 | 6,739 ms |
コンパイル使用メモリ | 167,000 KB |
実行使用メモリ | 185,176 KB |
最終ジャッジ日時 | 2024-09-27 16:05:23 |
合計ジャッジ時間 | 12,646 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (81 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
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;}}}