結果

問題 No.2541 Divide 01 String
ユーザー MaxdorianMaxdorian
提出日時 2023-11-24 21:33:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 5,266 ms
コンパイル使用メモリ 308,676 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-24 21:33:56
合計ジャッジ時間 6,261 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int INF = INT_MAX / 2;
const ll LINF = 1LL << 60;
const vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
using mint = modint998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      ok = true;
    }
  }
  if (!ok) {
    cout << 0 << '\n';
    return 0;
  }
  int r = 0;
  mint ans = 1;
  for (int l = 0; l < n;) {
    if (s[l] == '0') {
      l++;
      r++;
    } else {
      if (r < n - 1 && s[l] == '1' && s[r + 1] == '1') {
        ans *= 2;
        l++;
        r++;
        continue;
      }
      r++;
      while (r < n && s[r] == '0') {
        r++;
      }
      if (r == n) {
        break;
      } else {
        ans *= (r - l + 1);
        l = r;
      }
    }
  }
  cout << ans.val() << '\n';
  return 0;
}
0