結果

問題 No.3114 0→1
コンテスト
ユーザー t98slider
提出日時 2025-04-29 21:43:25
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WJ  
(最新)
AC  
(最初)
実行時間 -
コード長 614 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
最終ジャッジ日時 2026-10-16 03:29:25
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_0
このコードへのチャレンジ
(要ログイン)

ソースコード

diff #
raw source code

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    constexpr array<int,4> S = {0b011, 0b101, 0b110, 0b111};
    array<int, 8> dp{}, ndp;
    for(int i = 0; i < n; i++){
        ndp.fill(1 << 30);
        int c = s[i] - '0';
        for(auto U : S){
            int NU = U / 2 + 4 * c;
            ndp[NU] = min(ndp[NU], dp[U]);
            ndp[NU ^ 4] = min(ndp[NU ^ 4], dp[U] + 1);
        }
        dp = ndp;
    }
    int ans = 1 << 30;
    for(auto U : S) ans = min(ans, dp[U]);
    cout << ans << '\n';
}
0