이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Problem: P4 - Miners
// Contest: DMOJ - IOI '07
// URL: https://dmoj.ca/problem/ioi07p4
// Memory Limit: 16 MB
// Time Limit: 750 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define lg int
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const lg N = 1e5+5;
//lg dp[N][256];
lg n;
string s;
vector<lg> v(N);
// lg solve(lg idx, lg bit)
// {
// if(idx == n)
// {
// return 0;
// }
// auto &ret = dp[idx][bit];
// if(~ret) return ret;
// lg x = ((bit/64)&3), y = ((bit/16)&3), a = ((bit/4)&3), b = (bit&3);
// set<lg> se1;
// if(v[idx] != 3) se1.insert(v[idx]);
// if(x != 3) se1.insert(x);
// if(y != 3) se1.insert(y);
// set<lg> se2;
// if(v[idx] != 3) se2.insert(v[idx]);
// if(a != 3) se2.insert(a);
// if(b != 3) se2.insert(b);
// lg ch1 = solve(idx+1, v[idx]*64+x*16+a*4+b)+se1.size();
// lg ch2 = solve(idx+1, x*64+y*16+v[idx]*4+a)+se2.size();
// return ret = max(ch1, ch2);
// }
lg dp[2][N];
lg calc(lg a, lg b, lg c)
{
lg ans = 0;
for(int i = 0; i < 3; i++)
{
if(a == 0 || b == 0 || c == 0) ans++;
a--, b--, c--;
}
return ans;
}
int main()
{
fastio;
cin >> n >> s;
for(int i = 0; i < n; i++)
{
if(s[i] == 'M') v[i] = 1;
if(s[i] == 'B') v[i] = 2;
}
for(int i = n-1; i >= 0; i--)
{
for(int j = 0; j < 256; j++)
{
lg x = ((j>>6)&3), y = ((j>>4)&3), a = ((j>>2)&3), b = (j&3);
dp[i&1][j] = max(dp[!(i&1)][v[i]*64+x*16+a*4+b]+calc(v[i], x, y), dp[!(i&1)][x*64+y*16+v[i]*4+a]+calc(v[i], a, b));
}
}
cout << dp[0][255] << '\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... |