結果
| 問題 | 
                            No.3114 0→1
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-04-20 15:25:51 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 12 ms / 2,000 ms | 
| コード長 | 657 bytes | 
| コンパイル時間 | 2,064 ms | 
| コンパイル使用メモリ | 193,300 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-04-20 15:25:55 | 
| 合計ジャッジ時間 | 3,320 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int n;
string s;
void mark(int i) {
	s[i] = '1';
	ans++;
}
int main() {
	cin >> n >> s;
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	} else if (n == 2) {
		if (s == "11") cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	} else {
		for (int i = 0; i < (int)s.length() - 2; i++) {
			string t = s.substr(i,3);
			// cerr << t << endl;
			if (t == "000") {
				mark(i+1); mark(i+2);
			} else if (t == "001") {
				mark(i+1);
			} else if (t == "010") {
				mark(i+2);
			} else if (t == "100") {
				mark(i+2);
			} else {
				// more than 2 1s, fine
			}
		}
		cout << ans << endl;
	}
}