結果

問題 No.3500 01 String
コンテスト
ユーザー Yoyoyo8128
提出日時 2026-04-18 11:53:04
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 3,914 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,440 ms
コンパイル使用メモリ 222,380 KB
実行使用メモリ 13,136 KB
最終ジャッジ日時 2026-04-18 11:53:12
合計ジャッジ時間 4,302 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 6 WA * 13 RE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:200:5: warning: 'rig1' may be used uninitialized [-Wmaybe-uninitialized]
  200 |     if(lef0>rig1){
      |     ^~
main.cpp:187:13: note: 'rig1' was declared here
  187 |     ll lef0,rig1;
      |             ^~~~
main.cpp:200:5: warning: 'lef0' may be used uninitialized [-Wmaybe-uninitialized]
  200 |     if(lef0>rig1){
      |     ^~
main.cpp:187:8: note: 'lef0' was declared here
  187 |     ll lef0,rig1;
      |        ^~~~

ソースコード

diff #
raw source code

#pragma region Yoyoyo

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using i128t=__int128_t;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const string Yes="Yes";
const string No="No";
const long long inf=1ll<<60;

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

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr);
#define print(s) cout<<s<<endl;

template<typename T>
inline bool chmax(T &a,T b){return ((a<b)?(a=b,true):(false));}
template<typename T>
inline bool chmin(T &a,T b){return ((a>b)?(a=b,true):(false));}
template<typename T>
ll sum(const T&a){return accumulate(all(a),0LL);}

template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T,typename U>
istream &operator>>(istream &is,pair<T,U>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    int s=v.size();
    for(int i=0;i<s;i++){
        os<<(i?" ":"")<<v[i];
    }
    return os;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(auto &x:v){
        is>>x;
    }
    return is;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<vector<T>>&v){
    int s=v.size();
    for(int i=0;i<s;i++){
        os<<v[i]<<endl;
    }
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<vector<vector<T>>>&v){
    int s=v.size();
    for(int i=0;i<s;i++){
        os<<"i = "<<i<<endl;
        os<<v[i];
    }
    return os;
}

#ifdef LOCAL
template<class... Args>
void debug_out(Args... args){
    int _i=0;
    ((cerr<<(_i++?", ":" ")<<args), ...);
    cerr<<"\n";
}
#define debug(...){\
    cerr<<"["<<#__VA_ARGS__<<"]:";\
    debug_out(__VA_ARGS__);\
}
#else
#define debug(...)
#endif

#pragma endregion Yoyoyo

vector<int>dx={0,0,-1,1};
vector<int>dy={-1,1,0,0};

// 繰り返し二乗法
ll modpow(ll a, ll n, ll mod)
{
    if (a == 0)
    {
        return 0;
    }
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// 割り算
ll Div(ll a, ll b, ll m)
{
    return (a * modpow(b, m - 2, m)) % m;
}

// 階乗
vector<ll> fact(1);
void fac(ll N, ll m)
{
    fact[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        ll ppp = i;
        while (ppp % m == 0)
        {
            ppp /= m;
        }
        fact.pb(fact[i - 1] * (ppp));
        fact[i] %= m;
    }
}

ll v(ll n, ll p)
{
    ll aaans = 0;
    ll nppp = n;
    while (nppp > 0)
    {
        aaans += nppp / p;
        nppp /= p;
    }
    return aaans;
}
// 組み合わせ
ll comb(ll n, ll r, ll m)
{
    if (n < r)
    {
        return 0;
    }

    if (r < 0)
    {
        return 0;
    }

    if (n < 0)
    {
        return 0;
    }
    return Div(fact[n], fact[r] * fact[n - r] % m, m);
}

ll mod=998244353;

int main(){
    faster;
    ll M;cin>>M;
    string t;
    cin>>t;
    ll lef0,rig1;
    for(int i=0;i<M;i++){
        if(t[i]=='0'){
            lef0=i;
            break;
        }
    }
    for(int i=0;i<M;i++){
        if(t[i]=='1'){
            rig1=i;
            
        }
    }
    if(lef0>rig1){
        print(1);exit(0);
    }
    string s;
    for(int i=lef0;i<=rig1;i++)s+=t[i];
    ll N=s.size();
    int hen=0;
    fac(1000000,mod);
    for(int i=0;i<N-1;i++){
        if(s[i]!=s[i+1])hen++;
    }
    ll ans=0;
    for(int i=0;i<=hen;i++){
        ans+=comb(N-1,i,mod);
        ans%=mod;
    }
    for(int i=0;i<=hen-1;i++){
        ans+=comb(N-1,i,mod);
        ans%=mod;
    }
    cout<<ans<<"\n";
}
0