結果

問題 No.1239 Multiplication -2
ユーザー chocoruskchocorusk
提出日時 2020-09-25 22:23:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,793 bytes
コンパイル時間 1,138 ms
コンパイル使用メモリ 127,512 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 15:38:09
合計ジャッジ時間 3,763 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 34 ms
4,380 KB
testcase_17 AC 55 ms
4,380 KB
testcase_18 AC 69 ms
4,376 KB
testcase_19 AC 52 ms
4,380 KB
testcase_20 AC 59 ms
4,376 KB
testcase_21 AC 82 ms
4,380 KB
testcase_22 AC 63 ms
4,384 KB
testcase_23 AC 64 ms
4,380 KB
testcase_24 AC 49 ms
4,376 KB
testcase_25 AC 18 ms
4,380 KB
testcase_26 AC 56 ms
4,376 KB
testcase_27 AC 25 ms
4,380 KB
testcase_28 AC 76 ms
4,380 KB
testcase_29 AC 82 ms
4,376 KB
testcase_30 AC 32 ms
4,380 KB
testcase_31 AC 46 ms
4,376 KB
testcase_32 AC 78 ms
4,376 KB
testcase_33 AC 54 ms
4,376 KB
testcase_34 AC 51 ms
4,376 KB
testcase_35 AC 25 ms
4,376 KB
testcase_36 AC 23 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
const ll MOD=998244353;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
int main()
{
    int n; cin>>n;
    int a[200020];
    for(int i=0; i<n; i++) cin>>a[i];
    ll ans=0;
    for(int i=0; i<n; i++){
        if(abs(a[i])!=2) continue;
        int l=i-1, r=i+1;
        while(l>=0){
            if(abs(a[l])!=1) break;
            l--;
        }
        while(r<n){
            if(abs(a[r])!=1) break;
            r++;
        }
        ll sl[2]={}, sr[2]={};
        int p=0;
        for(int j=i; j>l; j--){
            if(j<i && a[j]==-1) p^=1;
            (sl[p]+=powmod(2, max(0, j-1)))%=MOD;
        }
        p=0;
        for(int j=i+1; j<=r; j++){
            if(j-1>i && a[j-1]==-1) p^=1;
            (sr[p]+=powmod(2, MOD-1-min(n-1, j)))%=MOD;
        }
        int p0=0;
        if(a[i]==-2) p0^=1;
        for(int p=0; p<2; p++){
            for(int q=0; q<2; q++){
                if(p^q^p0){
                    (ans+=sl[p]*sr[q])%=MOD;
                }
            }
        }
      //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}
0