結果

問題 No.3114 0→1
ユーザー karashi-0086A2
提出日時 2025-04-20 19:28:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 401 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 67,740 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-04-20 19:28:39
合計ジャッジ時間 2,206 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

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

    int ans = 0, balance = 0;

    for (char c : S) {
        if (c == '0') balance++;
        else balance--;

        if (balance > 0) {
            ans++;
            balance -= 2;  // 仮に 0 を 1 に変えたとする
        }
    }

    cout << ans << endl;
    return 0;
}
0