結果

問題 No.884 Eat and Add
ユーザー k0hn0yutal2l5k0hn0yutal2l5
提出日時 2019-09-13 22:10:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 657 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 52,328 KB
実行使用メモリ 5,336 KB
最終ジャッジ日時 2023-09-17 14:28:11
合計ジャッジ時間 1,215 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>

using namespace std;

int dp[200000][2];

int main()
{
    string S;
    cin >> S;
    if (S[0] == '0')
    {
        dp[0][0] = 0;
        dp[0][1] = 1;
    }
    else
    {
        dp[0][0] = 1;
        dp[0][1] = 0;
    }
    for (int i = 1; i < S.size(); i++)
    {
        if (S[i] == '0')
        {
            dp[i][0] = min(dp[i - 1][0], min(i, dp[i - 1][1] + 2));
            dp[i][1] = dp[i - 1][1] + 1;
        }
        else
        {
            dp[i][0] = min(dp[i - 1][0] + 1, dp[i - 1][1] + 2);
            dp[i][1] = dp[i - 1][1];
        }
    }
    cout << min(dp[S.size() - 1][0], dp[S.size() - 1][0] + 2) << endl;
}
0