結果

問題 No.3114 0→1
ユーザー GOTKAKO
提出日時 2025-04-18 20:54:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 192,704 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-18 20:54:37
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    string s; cin >> s;    
    int zero = 0,one = N*2,two = N*2;
    for(auto c : s){
        int n0 = N*2,n1 = N*2,n2 = N*2;
        if(c == '0'){
            n2 = zero;
            n0 = min({zero,one})+1;
            n1 = two+1;
        }
        else{
            n0 = min(zero,one);
            n1 = two;
        }
        zero = n0,one = n1,two = n2;
    }
    cout << min({zero,one,two}) << endl;
}
0