結果

問題 No.3114 0→1
ユーザー Hoang Nho Dinh
提出日時 2025-04-18 22:36:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 685 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 66,916 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-04-18 22:36:56
合計ジャッジ時間 1,960 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

int min_operations_to_good_string(const string& S) {
    int operations = 0;
    int zero_count = 0;
    int one_count = 0;

    for (char c : S) {
        if (c == '0') {
            zero_count++;
        } else {
            one_count++;
        }

        if (zero_count > one_count) {
            // Fix this zero by converting it to a one
            operations++;
            zero_count--;  // treat this 0 as now a 1
            one_count++;
        }
    }

    return operations;
}

int main() {
	int n;
	cin >> n;
    string S;
    cin >> S;

    cout << min_operations_to_good_string(S) << endl;

    return 0;
}
0