結果

問題 No.2219 Re:010
ユーザー nagisa5101nagisa5101
提出日時 2023-03-25 08:18:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,611 bytes
コンパイル時間 4,581 ms
コンパイル使用メモリ 265,632 KB
実行使用メモリ 8,404 KB
最終ジャッジ日時 2023-10-18 21:56:03
合計ジャッジ時間 6,389 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 43 ms
7,612 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 AC 35 ms
6,816 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 21 ms
5,352 KB
testcase_08 AC 40 ms
7,348 KB
testcase_09 AC 39 ms
7,084 KB
testcase_10 AC 30 ms
6,408 KB
testcase_11 AC 26 ms
5,880 KB
testcase_12 AC 25 ms
5,880 KB
testcase_13 AC 51 ms
8,404 KB
testcase_14 AC 51 ms
8,404 KB
testcase_15 AC 50 ms
8,404 KB
testcase_16 AC 50 ms
8,404 KB
testcase_17 AC 50 ms
8,404 KB
testcase_18 AC 7 ms
8,404 KB
testcase_19 AC 8 ms
8,404 KB
testcase_20 AC 69 ms
8,404 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (int i = n; i < (int)(m); i++)
#define repll2(i, n, m) for (long long i = n; i < (long long)(m); i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vvvl=vector<vvl>;
using vld=vector<ld>;
using vvld=vector<vld>;

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

const double PI = acos(-1);
//const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=(1LL<<60);
const int INF2=(1<<30);
//using mint=modint1000000007;
using mint=modint998244353;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s;cin>>s;
    int sz=s.size();
    vl cnt_0(sz+1,0),cnt_1(sz+1,1),cnt_q(sz+1,0);
    rep(i,sz){
        cnt_0[i+1]=cnt_0[i];
        cnt_1[i+1]=cnt_1[i];
        cnt_q[i+1]=cnt_q[i];
        if(s[i]=='0')cnt_0[i+1]++;
        else if(s[i]=='1')cnt_1[i+1]++;
        else cnt_q[i+1]++;
    }
    mint ans=0;
    ll cnt_q_all=cnt_q[sz];
    rep(i,sz){
        if(s[i]=='0')continue;
        else if(s[i]=='1'){
            //010,?10,01?,?0?
            ll cnt_0_l=cnt_0[i],cnt_0_r=cnt_0[sz]-cnt_0[i+1];
            ll cnt_q_l=cnt_q[i],cnt_q_r=cnt_q[sz]-cnt_q[i+1];

            ans+=cnt_0_l*cnt_0_r*mint(2).pow(cnt_q[sz]);
            //010
            if(cnt_q_all>0){
                ans+=cnt_q_l*cnt_0_r*mint(2).pow(cnt_q[sz]-1);
                //?10
                ans+=cnt_0_l*cnt_q_r*mint(2).pow(cnt_q[sz]-1);
                //01?
            }
            if(cnt_q_all>1){
                ans+=cnt_q_l*cnt_q_r*mint(2).pow(cnt_q[sz]-2);
                //?1?
            }
        }
        else{
            //0?0,??0,0??,???
            ll cnt_0_l=cnt_0[i],cnt_0_r=cnt_0[sz]-cnt_0[i+1];
            ll cnt_q_l=cnt_q[i],cnt_q_r=cnt_q[sz]-cnt_q[i+1];

            if(cnt_q_all>0)ans+=cnt_0_l*cnt_0_r*mint(2).pow(cnt_q[sz]-1);
            //0?0
            if(cnt_q_all>1)ans+=cnt_q_l*cnt_0_r*mint(2).pow(cnt_q[sz]-2);
            //??0
            if(cnt_q_all>1)ans+=cnt_0_l*cnt_q_r*mint(2).pow(cnt_q[sz]-2);
            //0??
            if(cnt_q_all>2)ans+=cnt_q_l*cnt_q_r*mint(2).pow(cnt_q[sz]-3);
            //???
        }
    }
    cout<<ans.val()<<endl;
    return 0;
}
0