[Offer收割]编程练习赛107 register

Ended

Participants:61

Verdict:Accepted
Score:100 / 100
Submitted:2019-09-01 12:58:43

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
void solve() {
    string s; s.reserve(1000006);
    cin >> s;
    int n = s.size();
    vector<pair<int, int>> a; a.reserve(400006);
    int i = 0;
    while (i < n) {
        int I = i;
        while (i<n && s[i]==s[I]) {
            i++;
        }
        if (i - I >= 3) {
            a.emplace_back(I, i);
        }
    }
    a.emplace_back(n-2, n);
    int res = 1;
    int crt = 0;
    for (auto& p: a) {
        int l,r;
        tie(l,r)=p;
        res = max(res, l+2-crt);
        crt = r-2;
    }
    cout << res;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX