Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <algorithm>
- using namespace std;
- typedef long long ll;
- int main()
- {
- int n;
- cin >> n;
- string s;
- cin >> s;
- int result = 0;
- if(n <= 20) {
- for(int mask = 0; mask < (1 << n); mask++) {
- string L = "";
- string R = "";
- for(int i = 0; i < n; i++) {
- if(mask & (1 << i)) {
- L += s[i];
- }
- else {
- R += s[i];
- }
- }
- int tmp = 0;
- reverse(L.begin(), L.end());
- reverse(R.begin(), R.end());
- for(int i = 0; i < L.size(); i++) {
- set<char> st;
- if(i + 2 < L.size()) {
- st.insert(L[i + 2]);
- }
- if(i + 1 < L.size()) {
- st.insert(L[i + 1]);
- }
- st.insert(L[i]);
- if((int) st.size() == 3) {
- tmp += 3;
- }
- else if((int) st.size() == 2) {
- tmp += 2;
- }
- else {
- tmp++;
- }
- }
- for(int i = 0; i < R.size(); i++) {
- set<char> st;
- if(i + 2 < R.size()) {
- st.insert(R[i + 2]);
- }
- if(i + 1 < R.size()) {
- st.insert(R[i + 1]);
- }
- st.insert(R[i]);
- if((int)st.size() == 3) {
- tmp += 3;
- }
- else if((int)st.size() == 2) {
- tmp += 2;
- }
- else {
- tmp++;
- }
- }
- result = max(result, tmp);
- }
- cout << result << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement