//by gemini 2.5Pro (流石にFlashに比べて賢そう?) #include #include #include #include // Not strictly needed for this solution but common include int main() { // Optimize C++ standard streams for faster I/O. std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int N; std::cin >> N; std::string s_str; std::cin >> s_str; // Convert the input string to a vector of characters for easy modification. std::vector s(s_str.begin(), s_str.end()); int operations = 0; // Iterate through the string from left to right. for (int i = 0; i < N; ++i) { // We only care if the current character s[i] is '0', as it might complete a bad pattern. if (s[i] == '0') { // Check for the "010" pattern ending at index i. // This pattern is s[i-2]s[i-1]s[i] == '0''1''0'. // For this, s[i] is '0', s[i-1] must be '1', and s[i-2] must be '0'. if (i >= 2 && s[i-1] == '1' && s[i-2] == '0') { s[i] = '1'; // Change s[i] to '1' to fix the pattern. operations++; // Increment the operation count. } // Else, if s[i] was not part of a "010" pattern (and thus not changed), // check for the "00" pattern ending at index i. // This pattern is s[i-1]s[i] == '0''0'. // For this, s[i] is '0', and s[i-1] must be '0'. // The 'else if' ensures this check only happens if the "010" fix was not applied to s[i]. else if (i >= 1 && s[i-1] == '0') { s[i] = '1'; // Change s[i] to '1' to fix the pattern. operations++; // Increment the operation count. } } } std::cout << operations << std::endl; return 0; }