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;
const int INF = 0x3fffffff;
#define all(a) begin(a), end(a)
#define each(i,a) for(auto&& i : a)
#define overload3(_1, _2, _3, name, ...) name
#define rep1(n) for(int i = 0; i < (n); ++i)
#define rep2(i, n) for(int i = 0; i < (n); ++i)
#define rep3(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
inline constexpr int kinds(int a, int b, int c){
int ans = 0;
rep(i, 1, 4) if(a == i || b == i || c == i) ans++;
return ans;
}
int main(){
string s;
cin >> s >> s;
each(i, s){
if(i == 'B') i = 1;
else if(i == 'F') i = 2;
else i = 3;
}
vector<int> dp1(1 << 8, -INF);
dp1[0] = 0;
each(c, s){
vector<int> dp2(1 << 8, -INF);
rep(1 << 8){
int a1 = i >> 6 & 3, a2 = i >> 4 & 3, b1 = i >> 2 & 3, b2 = i & 3;
int j = a2 << 6 | c << 4 | b1 << 2 | b2;
chmax(dp2[j], dp1[i] + kinds(a1, a2, c));
j = a1 << 6 | a2 << 4 | b2 << 2 | c;
chmax(dp2[j], dp1[i] + kinds(b1, b2, c));
}
swap(dp1, dp2);
}
cout << *max_element(all(dp1)) << endl;
}
# | 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... |