結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
onakaT_Titai
|
| 提出日時 | 2019-09-13 22:59:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 1,000 ms |
| コード長 | 932 bytes |
| コンパイル時間 | 1,607 ms |
| コンパイル使用メモリ | 170,892 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 10:15:37 |
| 合計ジャッジ時間 | 2,078 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(void){
string S; cin >> S;
S += '0';
vector<pair<int, pair<int, int>>> n;
int cnt = 0;
int s;
int t;
int l = 0;
for (int i = 0; i < S.length(); i++) {
if (S[i] == '1') {
if (l == 0) s = i;
l++;
} else {
if (l > 0) {
t = i-1;
n.push_back({l, {s, t}});
}
l = 0;
}
}
long long ans = 0;
for (int i = n.size() - 1; i >= 0; i--) {
auto p = n[i];
int l = p.first;
int s = p.second.first;
int t = p.second.second;
if (l == 1) {
ans++;
} else if (i != 0 && n[i-1].second.second + 2 == s) {
ans++;
n[i-1].first++;
n[i-1].second.second++;
} else {
ans += 2;
}
}
cout << ans << endl;
}
onakaT_Titai