#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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
483 ms |
372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1574 ms |
384 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1541 ms |
356 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
116 ms |
448 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1565 ms |
640 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
692 KB |
Output isn't correct |