結果
問題 | No.1741 Arrays and XOR Procedure |
ユーザー | nawawan |
提出日時 | 2021-11-12 22:47:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 3,978 bytes |
コンパイル時間 | 2,052 ms |
コンパイル使用メモリ | 207,520 KB |
実行使用メモリ | 18,416 KB |
最終ジャッジ日時 | 2024-11-25 20:34:58 |
合計ジャッジ時間 | 4,955 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 21 ms
14,080 KB |
testcase_01 | AC | 21 ms
14,028 KB |
testcase_02 | AC | 20 ms
14,076 KB |
testcase_03 | AC | 60 ms
18,256 KB |
testcase_04 | AC | 20 ms
14,080 KB |
testcase_05 | AC | 55 ms
18,304 KB |
testcase_06 | AC | 58 ms
18,304 KB |
testcase_07 | AC | 62 ms
18,416 KB |
testcase_08 | AC | 54 ms
18,380 KB |
testcase_09 | AC | 54 ms
17,664 KB |
testcase_10 | AC | 55 ms
17,792 KB |
testcase_11 | AC | 47 ms
16,752 KB |
testcase_12 | AC | 42 ms
16,288 KB |
testcase_13 | AC | 54 ms
17,408 KB |
testcase_14 | AC | 45 ms
16,392 KB |
testcase_15 | AC | 51 ms
17,168 KB |
testcase_16 | AC | 23 ms
14,280 KB |
testcase_17 | AC | 32 ms
15,092 KB |
testcase_18 | AC | 45 ms
16,544 KB |
testcase_19 | AC | 22 ms
14,152 KB |
testcase_20 | AC | 58 ms
18,176 KB |
testcase_21 | AC | 48 ms
16,952 KB |
testcase_22 | AC | 46 ms
16,684 KB |
testcase_23 | AC | 30 ms
15,064 KB |
testcase_24 | AC | 24 ms
14,444 KB |
testcase_25 | AC | 56 ms
18,112 KB |
testcase_26 | AC | 36 ms
15,728 KB |
testcase_27 | AC | 22 ms
14,280 KB |
testcase_28 | AC | 47 ms
16,832 KB |
testcase_29 | AC | 54 ms
17,280 KB |
testcase_30 | AC | 48 ms
16,788 KB |
testcase_31 | AC | 22 ms
14,336 KB |
testcase_32 | AC | 36 ms
15,732 KB |
testcase_33 | AC | 39 ms
16,108 KB |
testcase_34 | AC | 28 ms
14,768 KB |
testcase_35 | AC | 21 ms
13,988 KB |
testcase_36 | AC | 24 ms
14,464 KB |
testcase_37 | AC | 35 ms
15,524 KB |
testcase_38 | AC | 55 ms
18,176 KB |
testcase_39 | AC | 34 ms
15,452 KB |
testcase_40 | AC | 21 ms
14,208 KB |
testcase_41 | AC | 28 ms
14,808 KB |
testcase_42 | AC | 22 ms
14,336 KB |
testcase_43 | AC | 20 ms
14,028 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template<const int MOD> struct modint{ long long val; modint(): val(0) {} modint(long long x){ if(x < 0) val = x % MOD + MOD; else val = x % MOD; } modint(const modint &t){ val = t.val; } modint& operator =(const modint m){ val = m.val; return *this; } modint operator -(){ return modint(-val); } modint& operator-=(const modint &m){ val -= m.val; if(val < 0) val += MOD; return *this; } modint& operator+=(const modint &m){ val += m.val; if(val >= MOD) val -= MOD; return *this; } modint& operator*=(const modint &m){ val *= m.val; val %= MOD; return *this; } modint& operator/=(modint m){ *this *= m.inv(); return *this; } modint inv(){ long long x = 1, y = 0; long long a = val, b = MOD; while(b != 0){ long long t = a / b; a -= t * b; x -= t * y; swap(a, b); swap(x, y); } x %= MOD; if(x < 0) x += MOD; return modint(x); } modint pow(long long k){ long long res = 1; long long v = val; while(k > 0){ if(k & 1) res = res * v % MOD; v = v * v % MOD; k >>= 1; } return modint(res); } bool operator==(const modint &m){ return val == m.val; } modint operator+(const modint &m){ return modint(*this) += m; } modint operator-(const modint &m){ return modint(*this) -= m; } modint operator*(const modint &m){ return modint(*this) *= m; } modint operator/(const modint &m){ return modint(*this) /= m; } bool operator!=(const modint &m){ return modint(*this).val != m.val; } bool operator!=(const int &m){ return modint(*this).val != m; } }; const int MOD = 998244353; using mint = modint<MOD>; const int MAX = 410000; mint fac[MAX], finv[MAX], inv[MAX]; void COMinit(){ fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i; inv[i] = mint(MOD) - inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } } mint COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } int main(){ int N; cin >> N; vector<int> B(N); for(int i = 0; i < N; i++) cin >> B[i]; vector<vector<mint>> dp(2, vector<mint>(N)); vector<int> cnt(300000); for(int i = 1; i < 300000; i++){ int ni = 2; while(i >= ni){ cnt[i] += i / ni; ni *= 2; } } for(int i = 0; i < N; i++){ int rest = cnt[N - 1] - cnt[i] - cnt[N - 1 - i]; if(i == 0){ if(B[i] == -1){ dp[0][i] = 1; dp[1][i] = 1; } else{ dp[B[i]][i] = 1; } } else{ if(rest > 0){ if(B[i] == -1){ dp[1][i] = dp[1][i - 1] * 2; dp[0][i] = dp[0][i - 1] * 2; } else{ dp[1][i] = dp[1][i - 1]; dp[0][i] = dp[0][i - 1]; } } else{ if(B[i] == 0){ dp[0][i] = dp[0][i - 1]; dp[1][i] = dp[1][i - 1]; } else if(B[i] == 1){ dp[1][i] = dp[0][i - 1]; dp[0][i] = dp[1][i - 1]; } else{ dp[1][i] = dp[1][i - 1] + dp[0][i - 1]; dp[0][i] = dp[1][i - 1] + dp[0][i - 1]; } } } } cout << dp[1][N - 1].val << endl; }