結果

問題 No.3114 0→1
ユーザー AK_Mi
提出日時 2025-04-18 22:41:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,198 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 192,496 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2025-04-18 22:41:25
合計ジャッジ時間 8,260 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    int zero = 0;
    int one = 0;
    int count1 = 0;
    int count2 = 0;
    string s,ss;
    
    cin >> n >> s;
    ss = s;
    
    for(int i = 0; i < n; i++){
        if(s.at(i) == '1')continue;
        
        for(int t = i + 1; t < n; t++){
            if(s.at(t) == '1')one++;
            else zero++;
            
            if(zero > one){
                s.at(t) = '1';
                count1++;
                zero--;
                one++;
            }
        }
        
        zero = 0;
        one = 0;
    }

    for(int i = 0; i < n; i++){
        if(ss.at(i) == '0'){
            s.at(i) = '1';
            break;
        }
    }




    for(int i = 0; i < n; i++){
        if(ss.at(i) == '1')continue;
        
        for(int t = i + 1; t < n; t++){
            if(ss.at(t) == '1')one++;
            else zero++;
            
            if(zero > one){
                ss.at(t) = '1';
                count2++;
                zero--;
                one++;
            }
        }
        
        zero = 0;
        one = 0;
    }


    cout << min(count1,count2) << endl;


    
    return 0;
}
0