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;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
/// freopen ("input", "r", stdin);
int n;
string s;
cin >> n >> s;
function<int(deque<int>)> eval = [&] (deque<int> d) {
set<int> F;
for (auto &x : d) {
F.insert(x);
}
return (int) F.size();
};
function<int(deque<int>, int)> when = [&] (deque<int> d, int x) {
while ((int) d.size() < 2) d.push_front(-1);
assert((int) d.size() == 2);
if (d[0] == x && d[1] == x) return 10;
if (d[1] == x) return 2;
if (d[0] == x) return 1;
return -1;
};
int sol = 0;
deque<int> a, b;
for (int i = 1; i <= n; i++) {
if ((int) a.size() == 3) a.pop_front();
if ((int) b.size() == 3) b.pop_front();
int x = s[i - 1];
if (a.empty()) {a.push_back(x); sol += eval(a); continue;}
if (b.empty()) {b.push_back(x); sol += eval(b); continue;}
if ((int) a.size() == 1 && x != a[0]) {a.push_back(x); sol += eval(a); continue;}
if ((int) b.size() == 1 && x != b[0]) {b.push_back(x); sol += eval(b); continue;}
if (when(a, x) < when(b, x)) {
a.push_back(x);
sol += eval(a);
} else {
b.push_back(x);
sol += eval(b);
}
}
cout << sol << "\n";
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... |