結果

問題 No.884 Eat and Add
ユーザー outlineoutline
提出日時 2021-02-18 02:29:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 1,000 ms
コード長 1,505 bytes
コンパイル時間 1,331 ms
コンパイル使用メモリ 137,652 KB
実行使用メモリ 14,204 KB
最終ジャッジ日時 2023-10-12 12:09:36
合計ジャッジ時間 2,238 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 20 ms
14,204 KB
testcase_04 AC 19 ms
14,140 KB
testcase_05 AC 19 ms
14,204 KB
testcase_06 AC 19 ms
14,204 KB
testcase_07 AC 19 ms
14,120 KB
testcase_08 AC 18 ms
14,048 KB
testcase_09 AC 19 ms
14,152 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    reverse(begin(s), end(s));
    int n = s.length();
    vector<vector<int>> dp(n + 1, vector<int>(2, INF));
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == '0'){
            chmin(dp[i + 1][0], min(dp[i][0], dp[i][1] + 1));
            chmin(dp[i + 1][1], dp[i][1] + 1);
        }
        else{
            chmin(dp[i + 1][0], dp[i][0] + 1);
            chmin(dp[i + 1][1], min(dp[i][0] + 1, dp[i][1]));
        }
    }
    cout << min(dp[n][0], dp[n][1] + 1) << endl;

    return 0;
}
0