結果

問題 No.884 Eat and Add
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-09-13 22:24:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,131 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 94,820 KB
実行使用メモリ 5,216 KB
最終ジャッジ日時 2023-09-17 14:43:47
合計ジャッジ時間 1,492 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    int n  = s.length();
    vector<int> a(n, 0), ones(n+1, 0);
    for(int i=0;i<n;++i) a[i] = s[n-1-i] - '0';
    ones[0] = a[0];
    for(int i=1;i<n;++i) {
        ones[i] = ones[i-1] + a[i];
    }
    ones[n] = ones[n-1];

    int ans = 1<<30;
    for(int i=0;i<=n;++i) { // ここから上は1に揃える
        int c = ((i == 0) ? 0 : ones[i-1]);
        c += (n - i) - (ones[n] - ones[i-1]);
        if(i != n) c += 2;
        ans = min(ans, c);
    }

    cout << ans << endl;

}
0