#include <bits/stdc++.h>
using namespace std;
const long long INFll = 1e18;
const int INFii = 1e9;
const long long mod = (long long) 1e9 + 7;
typedef long long ll;
typedef int ii;
typedef double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define maxn 110000
//LEMBRAR DE MUDAR
ii n;
string s;
map<pair<pair<char,char>,pair<char,char>>, ll> dp[maxn];
ii sol(ii i, char a1, char a2, char b1, char b2) {
if(i == n) return 0;
if(dp[i].find(mp(mp(a1,a2),mp(b1,b2))) != dp[i].end()) {
return dp[i][mp(mp(a1,a2),mp(b1,b2))];
}
set<char> st1;
if(a1 != '0') st1.insert(a1);
if(a2 != '0') st1.insert(a2);
st1.insert(s[i]);
ii p1 = st1.size();
set<char> st2;
if(b1 != '0') st2.insert(b1);
if(b2 != '0') st2.insert(b2);
st2.insert(s[i]);
ii p2 = st2.size();
dp[i][mp(mp(a1,a2),mp(b1,b2))] = max(p1 + sol(i+1, s[i], a1, b1, b2), p2 + sol(i+1, a1, a2, s[i], b1));
return dp[i][mp(mp(a1,a2),mp(b1,b2))];
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
//freopen("in.in", "r", stdin);
//freopen("____.out", "w", stdout);
cin >> n;
cin >> s;
cout << sol(0, '0', '0', '0', '0') << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
7876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
12332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
253 ms |
32192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
619 ms |
65276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1200 ms |
151060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1601 ms |
200940 KB |
Time limit exceeded |