結果
| 問題 | 
                            No.3114 0→1
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ks2m
                         | 
                    
| 提出日時 | 2025-04-18 21:03:38 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 227 ms / 2,000 ms | 
| コード長 | 480 bytes | 
| コンパイル時間 | 2,268 ms | 
| コンパイル使用メモリ | 84,784 KB | 
| 実行使用メモリ | 60,132 KB | 
| 最終ジャッジ日時 | 2025-04-18 21:03:49 | 
| 合計ジャッジ時間 | 9,863 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		sc.close();
		int ans = 0;
		for (int i = 1; i < n; i++) {
			if (s[i - 1] == '0' && s[i] == '0') {
				ans++;
				s[i] = '1';
			}
			if (i >= 2 && s[i - 2] == '0' && s[i - 1] == '1' && s[i] == '0') {
				ans++;
				s[i] = '1';
			}
		}
		System.out.println(ans);
	}
}
            
            
            
        
            
ks2m