結果
| 問題 | 
                            No.1741 Arrays and XOR  Procedure
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ぷら
                         | 
                    
| 提出日時 | 2021-11-12 22:29:46 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,890 bytes | 
| コンパイル時間 | 1,696 ms | 
| コンパイル使用メモリ | 192,756 KB | 
| 最終ジャッジ日時 | 2025-01-25 17:05:28 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | RE * 3 | 
| other | AC * 19 RE * 22 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 998244353;
int dp[200001][2];
long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}
int main() {
    int N;
    cin >> N;
    dp[0][0] = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        int B;
        cin >> B;
        if(N%2 == 1) {
            assert(0);
            if(abs(N/2-i)%2 == 1) {
                for(int j = 0; j < 2; j++) {
                    if(B == 0 || B == -1) {
                        dp[i+1][j] += dp[i][j];
                        dp[i+1][j] %= mod;
                    }
                    if(B == 1 || B == -1) {
                        dp[i+1][j^1] += dp[i][j];
                        dp[i+1][j^1] %= mod;
                    }
                }
            }
            else {
                if(B == -1) {
                    cnt++;
                }
                for(int j = 0; j < 2; j++) {
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
        if(N%2 == 0) {
            if(i <= N/4*2 || i+N/4*2 >= N) {
                for(int j = 0; j < 2; j++) {
                    if(B == 0 || B == -1) {
                        dp[i+1][j] += dp[i][j];
                        dp[i+1][j] %= mod;
                    }
                    if(B == 1 || B == -1) {
                        dp[i+1][j^1] += dp[i][j];
                        dp[i+1][j^1] %= mod;
                    }
                }
            }
            else {
                if(B == -1) {
                    cnt++;
                }
                for(int j = 0; j < 2; j++) {
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
    }
    cout << modpow(2,cnt)*dp[N][1]%mod << endl;
}
            
            
            
        
            
ぷら