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_base::sync_with_stdio(0);
cin.tie(0);
int n, ans = 0;
string s, m1 = "", m2 = "";
cin >> n >> s;
for (int i = 0; i < n; i++) {
set<char> s1, s2;
if (m1.size() >= 2)
s1.insert(m1[m1.size() - 2]);
if (m1.size())
s1.insert(m1.back());
s1.insert(s[i]);
if (m2.size() >= 2)
s2.insert(m2[m2.size() - 2]);
if (m2.size())
s2.insert(m2.back());
s2.insert(s[i]);
if (i == n - 1) {
if (m1.empty()) {
m1 += s[i], ans += s1.size();
break;
}
if (m2.empty()) {
m2 += s[i], ans += s2.size();
break;
}
}
ans += max(s1.size(), s2.size());
if (s1.size() > s2.size())
m1 += s[i];
else if (s2.size() > s1.size())
m2 += s[i];
else
m1.size() < m2.size() ? m1 += s[i] : m2 += s[i];
}
cout << ans << "\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... |