This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair <pair<char,char>, pair<char,char>> T;
#define f(i,a,b) for(int i = a; i < b; i++)
int n;
string s;
int dif(char a, char b, char c){
set <char> ra;
if(a != '0') ra.insert(a);
if(b != '0') ra.insert(b);
if(c != '0') ra.insert(c);
return ra.size();
}
struct t{
char a = '0', b = '0', c = '0', d = '0';
int x = 0;
}wi;
int main(){
cin >> n >> s;
vector <t> a = {wi}, pos;
f(i,0,n){
pos.clear();
map <T, int> m;
for(t ra: a){
T WI_1, WI_2;
int w1_x = ra.x + dif(ra.a, ra.b, s[i]);
int w2_x = ra.x + dif(ra.c, ra.d, s[i]);
WI_1.first.first = ra.b, WI_1.first.second = s[i], WI_1.second.first = ra.c, WI_1.second.second = ra.d;
WI_2.first.first = ra.a, WI_2.first.second = ra.b, WI_2.second.first = ra.d, WI_2.second.second = s[i];
m[WI_1] = max(m[WI_1], w1_x);
m[WI_2] = max(m[WI_2], w2_x);
}
for(auto p: m){
t wi; T w = p.first;
//cout << w.first.first << " " << w.first.second << " " << w.second.first << " " << w.second.second << endl;
wi.x = p.second;
wi.a = w.first.first, wi.b = w.first.second, wi.c = w.second.first, wi.d = w.second.second;
pos.push_back(wi);
}
a.swap(pos);
}
int ans = 0;
for(auto p: a) ans = max(ans, p.x);
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |