이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int n;
string s;
map<pair<int, pair<deque<char>, deque<char>>>, int> dp;
int recurse(int index, deque<char> a, deque<char> b){
if(index == n)return 0;
if(dp[{index, {a, b}}])return dp[{index, {a, b}}];
set<int> sa, sb;
for(int i=0;i<a.size();i++)sa.insert(a[i]);
for(int i=0;i<b.size();i++)sb.insert(b[i]);
deque<char> qa = a, qb = b;
if(qa.size() == 2)qa.pop_front();
if(qb.size() == 2)qb.pop_front();
qa.pb(s[index]);
qb.pb(s[index]);
sa.insert(s[index]);
sb.insert(s[index]);
return dp[{index, {a, b}}] = max(sa.size() + recurse(index+1, qa, b) , sb.size() + recurse(index+1, a, qb));
}
void solve(){
cin >> n;
cin >> s;
deque<char> ep;
cout<<recurse(0, ep, ep);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int recurse(int, std::deque<char>, std::deque<char>)':
miners.cpp:17:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i<a.size();i++)sa.insert(a[i]);
| ~^~~~~~~~~
miners.cpp:18:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=0;i<b.size();i++)sb.insert(b[i]);
| ~^~~~~~~~~
# | 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... |