結果
問題 |
No.884 Eat and Add
|
ユーザー |
![]() |
提出日時 | 2019-09-13 23:14:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,390 bytes |
コンパイル時間 | 1,575 ms |
コンパイル使用メモリ | 171,548 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-04 10:24:40 |
合計ジャッジ時間 | 2,283 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define reps(i, n) for (int i = 0; i <= (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back typedef long long ll; typedef pair<int, int> P; const int inf = INT_MAX; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = s.size(); int cnt = 0; vector<int> a; vector<int> zero(n); rep(i, n-3) { if (s[i] == '1' && s[i+1] == '0' && s[i+2] == '1' && s[i+3] == '1') { zero[i+1] = 1; } else if (s[i] == '1' && s[i+1] == '1' && s[i+2] == '0' && s[i+3] == '1') { zero[i+2] = 1; } } int ans = 0; rep(i, n) { if (s[i] == '1') { cnt++; } else if (cnt && zero[i]) { ans++; } else if (cnt) { a.pb(cnt); cnt = 0; } } if (cnt) a.pb(cnt); // rep(i, a.size()) cout << a[i] << ' '; // cout << endl; rep(i, a.size()) { if (a[i] >= 2) { ans += 2; } else if (a[i] == 1) { ans++; } } cout << ans << endl; return 0; }