結果

問題 No.884 Eat and Add
ユーザー roundplusroundplus
提出日時 2019-09-23 17:06:13
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 1,000 ms
コード長 2,432 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 106,360 KB
実行使用メモリ 14,320 KB
最終ジャッジ日時 2023-08-20 12:56:26
合計ジャッジ時間 1,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    S += '0';
    int N = S.size();
    // コストが入る
    vector<vector<int>> dp(N + 1, vector<int>(2, 1e6));
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            if (S[i] == '0' && j == 0) {
                dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]);;
            } else if (S[i] == '1' && j == 1) {
                dp[i + 1][1] = min(dp[i + 1][1], dp[i][j]);
            } else {
                dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + 1);
                dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + 1);
            }
        }
    }
    cout << dp[N][0] << endl;
    return 0;
}
0