結果
| 問題 | 
                            No.3114 0→1
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-04-18 20:53:15 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 7 ms / 2,000 ms | 
| コード長 | 446 bytes | 
| コンパイル時間 | 2,025 ms | 
| コンパイル使用メモリ | 192,396 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-04-18 20:53:18 | 
| 合計ジャッジ時間 | 2,967 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N;
  cin>>S;
  if(N==1){
    cout<< 1-(S[0]-'0') <<endl;
    return 0;
  }
  if(N==2){
    cout<< 2-(S[0]-'0')-(S[1]-'0') <<endl;
  }
  int ans=0;
  for(int i=1;i<N;i++){
    if(S[i-1]=='0' && S[i] =='0'){
      S[i]='1';
      ans++;
    }
    if(i-2>=0 && S[i-2]=='0' && S[i]=='0'){
      S[i]='1';
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}