이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> operator + (vector<int> a, vector<int> b) {
for (auto &x : b) {
a.push_back(x);
}
return a;
}
vector<int> join(vector<int> a, vector<int> b) {
return a + vector<int> {-1} + b;
}
pair<vector<int>, vector<int>> split(vector<int> a) {
vector<int> x, y;
int cnt = 0;
for (auto &it : a) {
if (it == -1) {
cnt++;
continue;
}
if (cnt == 0) {
x.push_back(it);
} else {
y.push_back(it);
}
}
assert(cnt == 1);
return {x, y};
}
void upd(int pos, vector<int> a, vector<int> b, int value, vector<map<vector<int>, int>> &dp) {
vector<int> state = join(a, b);
if (!dp[pos].count(state)) {
dp[pos][state] = value;
} else {
dp[pos][state] = max(dp[pos][state], value);
}
}
int eval(vector<int> a) {
set<int> S;
for (auto &x : a) {
S.insert(x);
}
return (int) S.size();
}
vector<int> add(vector<int> a, int x) {
if ((int) a.size() == 2) {
a = {a[1], x};
return a;
}
assert((int) a.size() <= 1);
a.push_back(x);
return a;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n;
string s;
cin >> n >> s;
vector<map<vector<int>, int>> dp(n + 1);
upd(0, {}, {}, 0, dp);
for (int i = 0; i < n; i++) {
for (auto &v : dp[i]) {
auto it = split(v.first);
vector<int> a = it.first, b = it.second;
upd(i + 1, add(a, s[i]), b, v.second + eval(a + vector<int> {s[i]}), dp);
upd(i + 1, a, add(b, s[i]), v.second + eval(b + vector<int> {s[i]}), dp);
}
}
int best = -1;
for (auto &it : dp[n]) {
best = max(best, it.second);
}
cout << best << "\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... |