結果

問題 No.884 Eat and Add
ユーザー mdstoymdstoy
提出日時 2019-09-13 23:07:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,617 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 166,672 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 15:14:06
合計ジャッジ時間 2,428 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 9 ms
4,380 KB
testcase_05 AC 9 ms
4,380 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;

int main() {
    string s;
    cin >> s;
    int c = 0;

    // eating 1
    REP(i, s.size()) {
        if (s[i] == '1') c++;
    }

    // filling 0 -> +1 > eat
    int d = 0;
    REP(i, s.size()) {
        if (s[i] == '0') d++;
    }
    d += 2;

    reverse(ALL(s));
    int e = 0;
    bool r = false;
    REP(i, s.size()) {
        if (s[i] == '0') {
            if (r) {
                e++;
            }
        } else {
            if (!r) {
                e++;
                r = true;
            }
        }
    }
    e++;

    reverse(ALL(s));
    int f = 0;
    s += "0";
    size_t p;
    int q = 0;
    while ((p = s.find("0010", q)) != string::npos) {
        q = (int)p;
        s[q + 2] = '0';
        f++;
    }
    bool z = false;
    bool o = false;
    REP(i, s.size()) {
        if (s[i] == '1') {
            if (!o) {
                o = true;
                f += (z ? 2 : 1);
            }
        } else {
            if (o) {
                o = false;
                z = false;
            } else {
                z = true;
            }
        }
    }
    f++;

    cout << min({c, d, e, f}) << endl;
}
0