結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-13 23:07:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 1,000 ms |
| コード長 | 1,617 bytes |
| コンパイル時間 | 1,698 ms |
| コンパイル使用メモリ | 169,576 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 10:22:03 |
| 合計ジャッジ時間 | 2,334 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
#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;
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++;
reverse(ALL(s));
int f = 0;
s += "0";
size_t p;
int q = 0;
while ((p = s.find("0010", q)) != string::npos) {
q = (int)p;
s[q + 2] = '0';
f++;
}
bool z = false;
bool o = false;
REP(i, s.size()) {
if (s[i] == '1') {
if (!o) {
o = true;
f += (z ? 2 : 1);
}
} else {
if (o) {
o = false;
z = false;
} else {
z = true;
}
}
}
f++;
cout << min({c, d, e, f}) << endl;
}