結果

問題 No.2894 Monotonic Intervals
ユーザー GOTKAKOGOTKAKO
提出日時 2024-09-20 21:22:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 203,904 KB
実行使用メモリ 8,148 KB
最終ジャッジ日時 2024-09-20 21:22:21
合計ジャッジ時間 2,974 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 7 ms
5,552 KB
testcase_08 AC 7 ms
5,808 KB
testcase_09 AC 11 ms
8,084 KB
testcase_10 AC 6 ms
5,968 KB
testcase_11 AC 11 ms
8,016 KB
testcase_12 AC 12 ms
8,148 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
vector<pair<T,long long>> RLE(vector<T> &A){
    if(A.size() == 0) return {};
    vector<pair<T,long long>> ret;
    T back = A.at(0);
    long long streak = 1;
    for(int i=1; i<A.size(); i++){
        if(back == A.at(i)) streak++;
        else{
            ret.push_back({back,streak});
            back = A.at(i); streak = 1;
        }
    }
    ret.push_back({back,streak});
    return ret;
}
vector<pair<char,long long>> RLE(string &s){
    if(s.size() == 0) return {};
    vector<pair<char,long long>> ret;
    char back = s.at(0);
    long long streak = 1;
    for(int i=1; i<s.size(); i++){
        if(back == s.at(i)) streak++;
        else{
            ret.push_back({back,streak});
            back = s.at(i); streak = 1;
        }
    }
    ret.push_back({back,streak});
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N; cin >> N;
    string s; cin >> s;
    int answer = 0;
    auto S = RLE(s);
    cout << S.size() << endl;
}
0