結果

問題 No.884 Eat and Add
ユーザー ganariyaganariya
提出日時 2019-09-22 23:31:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 1,764 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 146,608 KB
実行使用メモリ 14,504 KB
最終ジャッジ日時 2023-10-19 07:27:33
合計ジャッジ時間 2,262 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

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)) {
                dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]);
            } else if (S[i] == '1' && (j)) {
                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);
            }
        }
    }

    int ans = (dp[N][0]);
    cout << ans << endl;

    return 0;
}


































0