結果
| 問題 | No.3500 01 String |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 00:52:29 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 940 bytes |
| 記録 | |
| コンパイル時間 | 241 ms |
| コンパイル使用メモリ | 39,424 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-18 00:52:31 |
| 合計ジャッジ時間 | 1,474 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <stdio.h>
#include <string.h>
#define MOD 998244353LL
#define MAXN 500005
char s[MAXN];
int main() {
int N;
scanf("%d", &N);
scanf("%s", s);
long long ans = 1;
int i = 0;
while (i < N) {
if (s[i] == '1') {
// pure 1-run: contributes 1
while (i < N && s[i] == '1') i++;
} else {
// zero-run
int a = 0;
while (i < N && s[i] == '0') {
a++;
i++;
}
// if followed by one-run, this pair contributes (a+b+1)
if (i < N && s[i] == '1') {
int b = 0;
while (i < N && s[i] == '1') {
b++;
i++;
}
ans = (ans * (a + b + 1LL)) % MOD;
}
// else: trailing pure 0-run, contributes 1
}
}
printf("%lld\n", ans % MOD);
return 0;
}