結果

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

ソースコード

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 + count1)+1;
            }
        }
        System.out.println(ans%998244353);

    }
}
0