結果

問題 No.884 Eat and Add
ユーザー mdstoymdstoy
提出日時 2019-09-13 22:54:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,634 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 166,668 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 15:04:08
合計ジャッジ時間 2,274 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 6 ms
4,384 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 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;

    int f = 0;
    bool z = false;
    bool o = false;
    REP(i, s.size()) {
        if (s[i] == '1') {
            if (!o) {
                if (i == s.size() - 1 || s[i + 1] == '0') {
                    f++;
                    o = false;
                    z = false;
                } else {
                    o = true;
                    f += (z ? 2 : 1);
                }
            }
        } else {
            if (o) {
                o = false;
                z = false;
            } else {
                z = true;
            }
        }
    }
    f++;

    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++;

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