이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
int n;
string s;
gp_hash_table<ll, ll> dp;
ll hashit(int &k, deque<char> &a, deque<char> &b){
ll ans = 0;
for(int i=0;i<a.size();i++){
ans ^= (a[i] - 'A');
}
for(int j=0;j<b.size();j++){
ans ^= (b[j] - 'A');
}
return (k*n) + (ans);
}
int recurse(int index, deque<char> &a, deque<char> &b){
if(index == n)return 0;
if(dp[hashit(index, a, b)])return dp[hashit(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[hashit(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, ep2;
cout<<recurse(0, ep, ep2);
}
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 'long long int hashit(int&, std::deque<char>&, std::deque<char>&)':
miners.cpp:20:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
miners.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int j=0;j<b.size();j++){
| ~^~~~~~~~~
miners.cpp: In function 'int recurse(int, std::deque<char>&, std::deque<char>&)':
miners.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<a.size();i++)sa.insert(a[i]);
| ~^~~~~~~~~
miners.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | 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... |