結果

問題 No.884 Eat and Add
コンテスト
ユーザー Mayimg
提出日時 2019-09-25 04:20:02
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 5 ms / 1,000 ms
+ 732µs
コード長 548 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,275 ms
コンパイル使用メモリ 219,556 KB
実行使用メモリ 9,896 KB
最終ジャッジ日時 2026-10-30 14:16:16
合計ジャッジ時間 2,615 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  vector<int> dp(2, 1 << 30);
  dp[0] = 0;
  for (char c : s) {
    vector<int> nxt(2);
    int x = c - '0';
    if (x == 0) {
      nxt[0] = min(dp[0], dp[1] + 1);
      nxt[1] = dp[1] + 1;
    }
    if (x == 1) {
      nxt[0] = dp[0] + 1;
      nxt[1] = min(dp[0] + 1, dp[1]);
    }
    swap(dp, nxt);
  }
  cout << min(dp[0], dp[1] + 1) << '\n';
  return 0;
}
0