結果

問題 No.3500 01 String
コンテスト
ユーザー MaTi
提出日時 2026-04-19 19:15:24
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,690 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,300 ms
コンパイル使用メモリ 331,040 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-19 19:15:37
合計ジャッジ時間 3,245 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 17 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,a,b) for (int i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a; i>=b; i--)
#define fore(i,a) for(auto &i:a)
#define pb push_back
#define _GLIBCXX_DEBUG
template <typename T> inline bool chmin(T& a, const T& b) {bool c=a>b; if(a>b) a=b; return c;}
template <typename T> inline bool chmax(T& a, const T& b) {bool c=a<b; if(a<b) a=b; return c;}
template <typename T> inline T gcd(T a,T b) {return (b==0)?a:gcd(b,a%b);}
template <typename T> inline T lcm(T a, T b) {return (a*b)/gcd(a,b);}
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  ll MOD = 998244353;
  cin >> n;
  string a;
  cin >> a;
  
  char bef;
  bool init = false;
  int cnt = 0;
  ll ans = 0;
  
  rep(i,0,n){
    if(!init){
      if(a.at(i) == '0'){
        init = true;
        cnt = 2;
        bef = '0';
      }
    } else{
      if(bef == '1' and a.at(i) == '0'){
        if(ans == 0){
          ans = cnt;
        } else{
          ans *= cnt;
        }
        ans %= MOD;
        cnt = 2;
        bef = '0';
      } else if(a.at(i) == '1' and i == n-1){
        if(ans == 0){
          ans = cnt+1;
        } else{
          ans *= cnt+1;
        }
        ans %= MOD;
      }
      else{
        cnt ++;
        bef = a.at(i);
      }
    }
  }
  
  cout << ans << endl;
  
  cout << fixed << setprecision(30);
  return 0;
}
0