이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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.size() == 2) {
m1 += s[i], ans += s1.size();
break;
}
if (m2.size() == 2) {
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... |