結果

問題 No.3114 0→1
ユーザー jupiter_68
提出日時 2025-04-14 13:02:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 69,700 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-15 20:43:38
合計ジャッジ時間 2,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
using namespace std;

int main() {
    int N, ans;
    string S;
    cin >> N >> S;
    ans = 0;
    if(N == 1){
        cout << ans << endl;
        return 0;
    }
    if(S[0] == '0' && S[1] == '0'){
        ans++;
        S[1] = '1';
    }
    for(int i = 2; i < N; i++){
        if(S[i] == '0'){
            if(S[i-1] == '0' || S[i-2] == '0'){
                ans++;
                S[i] = '1';
            }
        }
    }
    cout << ans << '\n';
    return 0;
}
0