結果

問題 No.884 Eat and Add
ユーザー onakaT_TitaionakaT_Titai
提出日時 2019-09-13 22:59:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 932 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 169,268 KB
実行使用メモリ 4,952 KB
最終ジャッジ日時 2023-09-17 15:06:15
合計ジャッジ時間 2,607 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0