結果

問題 No.884 Eat and Add
ユーザー ngtkanangtkana
提出日時 2019-09-13 21:49:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 199,976 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 07:08:30
合計ジャッジ時間 2,760 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  std::string t;
  auto x = 2, y = 0, z = 0;
  int nx = 0, ny = 0, nz = 0;
  constexpr int inf = 1'000'000'000;
  for (auto c : s) {
    t.push_back(c);
    if (c == '0') {
      nx = x + 1;
      ny = inf;
      nz = std::min({x, y, z});
    } else {
      nx = x;
      ny = std::min({x, y, z}) + 1;
      nz = inf;
    }
    cmn(nx, inf);
    cmn(ny, inf);
    cmn(nz, inf);
    std::swap(x, nx);
    std::swap(y, ny);
    std::swap(z, nz);
    // debug(x, y, z, t);
  }
  std::cout << std::min({x, y, z}) << std::endl;
  return 0;
}
0