結果

問題 No.884 Eat and Add
ユーザー たこしたこし
提出日時 2019-10-27 17:22:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,505 bytes
コンパイル時間 3,036 ms
コンパイル使用メモリ 199,944 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2023-10-12 22:54:30
合計ジャッジ時間 2,925 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,508 KB
testcase_01 AC 3 ms
6,464 KB
testcase_02 AC 3 ms
6,452 KB
testcase_03 AC 9 ms
6,676 KB
testcase_04 AC 9 ms
6,636 KB
testcase_05 AC 9 ms
6,604 KB
testcase_06 AC 9 ms
6,784 KB
testcase_07 AC 8 ms
6,592 KB
testcase_08 AC 8 ms
6,688 KB
testcase_09 AC 8 ms
6,632 KB
testcase_10 AC 4 ms
6,532 KB
testcase_11 AC 4 ms
6,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
int N;
string S;

int dp[MAX_N][2];

signed main()
{
  cin >> S; N = S.size();
  reverse(begin(S), end(S));

  REP(n,MAX_N) {
    dp[n][0] = dp[n][1] = INF;
  }

  dp[0][0] = 0;

  REP(n,N) {
    if(S[n] == '0') {
      dp[n+1][0] = min(dp[n+1][0], dp[n][0]);
      
      dp[n+1][0] = min(dp[n+1][0], dp[n][1] + 1);
      dp[n+1][1] = min(dp[n+1][1], dp[n][1] + 1);
    } else {
      dp[n+1][0] = min(dp[n+1][0], dp[n][0]+1);
      dp[n+1][1] = min(dp[n+1][1], dp[n][0]+1);
      
      dp[n+1][1] = min(dp[n+1][1], dp[n][1]);
    }
  }

  cout << min(dp[N][0], dp[N][1]+1) << endl;

  return 0;
}
0