結果
問題 |
No.3114 0→1
|
ユーザー |
|
提出日時 | 2025-05-21 15:54:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,850 bytes |
コンパイル時間 | 1,109 ms |
コンパイル使用メモリ | 99,908 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-21 15:54:32 |
合計ジャッジ時間 | 2,475 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
//by gemini 2.5Pro (流石にFlashに比べて賢そう?) #include <iostream> #include <vector> #include <string> #include <algorithm> // 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<char> 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; }