結果

問題 No.3114 0→1
コンテスト
ユーザー Hoang Nho Dinh
提出日時 2025-04-18 23:03:40
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WJ  
(最新)
AC  
(最初)
実行時間 -
コード長 462 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
最終ジャッジ日時 2026-10-17 20:34:01
ジャッジサーバーID
(参考情報)
judge6_0 / judge1_0
このコードへのチャレンジ
(要ログイン)

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	s = "." + s;
	int ans = 0;
	for(int i = 3; i <= n; i++) {
		int cnt = (s[i - 2] == '0') + (s[i - 1] == '0') + (s[i] == '0');
		if (cnt == 3) {
			s[i - 1] = '1';
			s[i] = '1';
			ans += 2;
		}
		else if (cnt == 2) {
			if (s[i] == '0') {
				s[i] = '1';
				ans++;
			}
			else if (s[i - 1] == '0') {
				s[i - 1] = '1';
				ans++;
			}
		}
	}
	cout << ans;
}
0