結果

問題 No.3114 0→1
コンテスト
ユーザー ardririy
提出日時 2025-04-19 13:26:16
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,621 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,015 ms
コンパイル使用メモリ 204,600 KB
最終ジャッジ日時 2026-07-09 22:58:36
合計ジャッジ時間 1,610 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:76,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/algorithm:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
                 from e.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bit: In instantiation of 'constexpr int std::__popcount(_Tp) [with _Tp = long long int]':
e.cpp:45:26:   required from here
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bit:308:34: error: argument 1 in call to function '__builtin_popcountg' has signed type
  308 |       return __builtin_popcountg(__x);
      |                                  ^~~

ソースコード

diff #
raw source code

#line 1 "e.cpp"
#include <bits/stdc++.h>
#line 1 "/home/ardririy/repos/cp-libs/libraries-cpp/input.hpp"



#line 7 "/home/ardririy/repos/cp-libs/libraries-cpp/input.hpp"

using namespace std;

vector<long long> i64_vec_IN(int n) {
    vector<long long> res(n);
    for(int i=0; i<n; i++) {
        cin >> res[i];
    }
    return res;
}

vector<string> str_vec_IN(int n) {
    vector<string> res(n);
    for(int i=0; i<n; i++) {
        cin >> res[i];
    }
    return res;
}

vector<vector<int>> graph_IN(int n, int m) {
    vector<vector<int>> g(n);
    int u, v;
    for(int i=0; i<m; i++) {
        cin >> u >> v;
        u--;
        v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    return g;
}


#line 3 "e.cpp"

using namespace std;

// using namespace atcoder;

#define all(v) v.begin(),v.end()
#define resort(v) sort(v.rbegin(),v.rend())
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;
using djks=priority_queue<P, vp, greater<P>>;

const ll inf=1ll<<60;
#define mod10 (ll)1e9+7
#define mod99 (ll)998244353
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=a;i<n;++i)
#define per2(i,a,n) for (ll i=n-1;i>=a;--i)


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

ll dx[] = {1, 0, -1, 0, -1, 1, -1, 1};
ll dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

void solve() {
    int n; cin >> n;
    string s; cin >> s;
    vvll dp(n+1, vll(4, inf));
    dp[0][3] = 0; // '11'からの続きとして見る
    rep(i,n) {
        ll v = s[i]-'0';
        rep2(j,1,4) {
            // cerr << "dp[" << i << "][" << j << "]= " << dp[i][j] << '\n';
            if(dp[i][j]==inf) continue;
            if(__popcount(j) == 1) {
                int nj = ((j<<1) | 1) & 3; // 1で埋めないとだめ
                chmin(dp[i+1][nj], dp[i][j] + 1-v);
            } else {
                // 1を使う
                int nj = ((j<<1) | 1) & 3;
                chmin(dp[i+1][nj], dp[i][j] + 1-v);
                if(v==0) {
                    nj = (j<<1) & 3;
                    chmin(dp[i+1][nj], dp[i][j]);
                }
            }
        }
    }
    ll ans = inf;
    rep2(i,1,4) chmin(ans, dp[n][i]);
    cout << ans << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t=1;
    //cin >> t;
    while(t--)solve();
}


0