結果
| 問題 | No.2541 Divide 01 String | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-11-24 21:46:24 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 5 ms / 2,000 ms | 
| コード長 | 678 bytes | 
| コンパイル時間 | 2,057 ms | 
| コンパイル使用メモリ | 197,768 KB | 
| 最終ジャッジ日時 | 2025-02-17 23:57:39 | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using mint = atcoder::modint998244353;
int main() {
  cin.tie(0); cout.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int L = N, R = -1;
  for(int i = 0; i < N; i++) {
    if(S[i] == '1') {
      L = min(L, i);
      R = max(R, i);
    }
  }
  if(L == N) {
    cout << 0 << '\n';
  } else {
    int cnt = 2;
    mint ans = 1;
    for(int i = L + 1; i <= R; i++) {
      if(S[i] == '1') {
        ans *= cnt;
        cnt = 1;
      }
      cnt++;
    }
    cout << ans.val() << '\n';
  }
  return 0;
}
            
            
            
        