제출 #119838

#제출 시각아이디문제언어결과실행 시간메모리
119838dolphingarlicMiners (IOI07_miners)C++14
45 / 100
1574 ms692 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for(ll i = x; i < y; i++)
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    FOR(i, 0, (1<<n)) {
        ll cp = i;
        deque<char> a, b;
        ll tot = 0;
        FOR(j, 0, n) {
            if (cp & 1) {
                a.push_back(s[j]);
                if (a.size() > 3) a.pop_front();
                if (a.size() == 1) tot++;
                else if (a.size() == 2) {
                    if (a[0] == a[1]) tot++;
                    else tot += 2;
                }
                else {
                    if (a[0] == a[1] && a[0] == a[2]) tot++;
                    else if (a[0] == a[2] || a[1] == a[2] || a[0] == a[1]) tot += 2;
                    else tot += 3;
                }
            } else {
                b.push_back(s[j]);
                if (b.size() > 3) b.pop_front();
                if (b.size() == 1) tot++;
                else if (b.size() == 2) {
                    if (b[0] == b[1]) tot++;
                    else tot += 2;
                }
                else {
                    if (b[0] == b[1] && b[0] == b[2]) tot++;
                    else if (b[0] == b[2] || b[1] == b[2] || b[0] == b[1]) tot += 2;
                    else tot += 3;
                }
            }
            cp >>= 1;
        }
        ans = max(ans, tot);
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...