結果

問題 No.1741 Arrays and XOR Procedure
ユーザー monnu
提出日時 2021-11-12 22:39:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 3,276 ms
コンパイル使用メモリ 228,836 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-25 20:14:22
合計ジャッジ時間 5,219 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,ll>>>;
#define INF 1000000000
#define MOD 998244353
#define MAX 300000

int main(){
  int N;
  cin>>N;
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>B[i];
  }

  vector<int> cnt(N,0);
  for(int i=1;i<N;i++){
    int x=i;
    cnt[i]=cnt[i-1];
    while(x%2==0){
      x/=2;
      cnt[i]++;
    }
  }

  int x=0;
  for(int i=0;i<N;i++){
    if(B[i]==1&&cnt[N-1]-cnt[i]-cnt[(N-1)-i]==0){
      x=1-x;
    }
  }
  ll zero=0;
  ll one=0;
  if(x==0){
    zero=1;
  }else{
    one=1;
  }

  for(int i=0;i<N;i++){
    if(B[i]==-1){
      if(cnt[N-1]-cnt[i]-cnt[(N-1)-i]==0){
        ll sum=(zero+one)%MOD;
        zero=sum;
        one=sum;
      }else{
        zero=2*zero%MOD;
        one=2*one%MOD;
      }
    }
  }
  cout<<one<<'\n';
}
0