結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-13 22:54:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,634 bytes |
| コンパイル時間 | 1,599 ms |
| コンパイル使用メモリ | 169,228 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 10:14:19 |
| 合計ジャッジ時間 | 2,213 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 5 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
int main() {
string s;
cin >> s;
int c = 0;
// eating 1
REP(i, s.size()) {
if (s[i] == '1') c++;
}
// filling 0 -> +1 > eat
int d = 0;
REP(i, s.size()) {
if (s[i] == '0') d++;
}
d += 2;
int f = 0;
bool z = false;
bool o = false;
REP(i, s.size()) {
if (s[i] == '1') {
if (!o) {
if (i == s.size() - 1 || s[i + 1] == '0') {
f++;
o = false;
z = false;
} else {
o = true;
f += (z ? 2 : 1);
}
}
} else {
if (o) {
o = false;
z = false;
} else {
z = true;
}
}
}
f++;
reverse(ALL(s));
int e = 0;
bool r = false;
REP(i, s.size()) {
if (s[i] == '0') {
if (r) {
e++;
}
} else {
if (!r) {
e++;
r = true;
}
}
}
e++;
cout << min({c, d, e, f}) << endl;
}