이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
cin >> n >> s;
char cur1 = '?', prev1 = '?';
char cur2 = '?', prev2 = '?';
int ans = 0;
string A, B;
for (int i=0; i<n; i++) {
set<char> a, b;
a.insert(s[i]);
if (cur1 != '?') a.insert(cur1);
if (prev1 != '?') a.insert(prev1);
b.insert(s[i]);
if (cur2 != '?') b.insert(cur2);
if (prev2 != '?') b.insert(prev2);
ans = ans + max((int)a.size(),(int)b.size());
if ((int)a.size() > (int)b.size()) {
prev1 = cur1;
cur1 = s[i];
A.push_back(s[i]);
}
if ((int)a.size() < (int)b.size()) {
prev2 = cur2;
cur2 = s[i];
B.push_back(s[i]);
}
if ((int)a.size() == (int)b.size()) {
if ((int)A.size() >= (int)B.size()) {
prev2 = cur2;
cur2 = s[i];
B.push_back(s[i]);
}
else {
prev1 = cur1;
cur1 = s[i];
A.push_back(s[i]);
}
}
}
cout << ans;
}
# | 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... |