結果

問題 No.3500 01 String
コンテスト
ユーザー nuigurumi
提出日時 2026-04-19 12:18:54
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
WA  
実行時間 -
コード長 1,216 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,106 ms
コンパイル使用メモリ 82,332 KB
実行使用メモリ 48,380 KB
最終ジャッジ日時 2026-04-19 12:19:03
合計ジャッジ時間 5,266 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int tail = 0;
        int current = 0;
        for(int i =0; i< N; i++){
            if(S.charAt(i) == '0'){
                tail = i;
                break;
            }
            if(i == N-1){
            System.out.println(1);
            return;
            }
        }
        
        int count0 = 0;
        int count1 = 0;
        long ans = 1;
        long tmp = 0;
        for(int i = tail; i < N; i++){
            if(S.charAt(i) == '0' && current == 0){
                count0++;
            }else if(S.charAt(i) == '1'){
                count1++;
                current = 1;
            }else if(S.charAt(i) == '0' && current == 1){
                tmp = count0 + count1;
                ans *= tmp+1;
                count0 = 1;
                count1 = 0;
                current = 0;
                tmp = 0;
            }
            if(current == 1 && i == N-1){
                ans *= (count0 + 1)+1;
            }
        }
        System.out.println(ans%998244353);

    }
}
0