結果

問題 No.884 Eat and Add
ユーザー face4face4
提出日時 2019-09-13 21:57:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 657 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 73,304 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 07:13:53
合計ジャッジ時間 1,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vector<int> v;
    for(int i = 0; i < n;){
        char c = s[i];
        int cnt = 1;
        while(i+1 < n && c == s[i+1])   cnt++, i++;
        i++;
        v.push_back(cnt);
    }
    int ans = 0;
    for(int i = 0; i < v.size();){
        bool notone = v[i] != 1;
        int cnt = 1;
        i += 2;
        while(i < v.size() && v[i-1] == 1){
            cnt++;
            notone |= (v[i] != 1);
            i += 2;
        }
        ans += cnt + (notone);
    }
    cout << ans << endl;
    return 0;
}
0