이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Contest: IOI'07 D2 P1
//Problem: Miners
//Link: https://oj.uz/problem/view/IOI07_miners
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define lg long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);
#define endl \n
#define lbound(x, y) lower_bound(x.begin(), x.end(), y)
#define ubound(x, y) upper_bound(x.begin(), x.end(), y)
#define sortasc(v) sort(v.begin(), v.end())
#define sortdesc(v) sort(v.rbegin(), v.rend())
#define custom_array(a,l, r) int _##a[r-l+1]; int*a=_##a-l;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const lg MOD = 1e9+7, N = 5e4+5, M = 1e7+1, SZ = 1e3+1;
/*
bitset<N> primes;
lg pwrs[N], inv[N];
lg fast_power(lg n, lg k)
{
if(!k) return 1;
if(k&1) return (fast_power(n, k-1)*n)%MOD;
lg x = fast_power(n, k/2)%MOD;
return (x*x)%MOD;
}
void sieve()
{
primes.set();
primes[0] = primes[1] = 0;
for(lg i = 2; i < N; i++)
{
if(!primes[i]) continue;
for(lg j = i*i; j < N; j += i)
{
primes[j] = 0;
}
}
return;
}
struct matrix
{
vector<vector<lg>> con = vector<vector<lg>> (SZ, vector<lg> (SZ));
matrix operator *(const matrix& a)
{
matrix product;
for(int i = 0; i < (lg)con.size(); i++)
{
for(int j = 0; j < (lg)a.con[0].size(); j++)
{
for(int k = 0; k < (lg)a.con.size(); k++)
{
product.con[i][j] = (product.con[i][j]+(con[i][k]*a.con[k][j])%MOD)%MOD;
}
}
}
return product;
}
};
void preprocess(lg x)
{
inv[2e5] = fast_power(x, MOD-2);
for(int i = 2e5-1; i > 1; i--)
{
inv[i] = (inv[i+1]*i)%MOD;
}
pwrs[0] = 1;
for(int i = 1; i <= 2e5; i++)
{
pwrs[i] = (pwrs[i]*i)%MOD;
}
return;
}
*/
lg dp[N][4][4][4];
lg n;
string s;
vector<lg> v(N);
lg solve(lg idx, lg x, lg y, lg z)
{
if(idx == n)
{
return 0;
}
auto &ret = dp[idx][x][y][z];
if(~ret) return ret;
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;
se2.insert(v[idx]);
lg cur = idx;
vector<lg> vis(3);
lg t = 0;
while(cur-- && t != 2)
{
if(!vis[0] && x == v[cur])
{
vis[0] = true;
}
else if(!vis[1] && y == v[cur])
{
vis[1] = true;
}
else if(!vis[2] && z == v[cur])
{
vis[2] = true;
}
else{
se2.insert(v[cur]);
t++;
}
}
lg ch1 = solve(idx+1, v[idx], x, y)+se1.size();
lg ch2 = solve(idx+1, x, y, z)+se2.size();
return ret = max(ch1, ch2);
}
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 j = 0; j < 4; j++)
{
for(int k = 0; k < 4; k++)
{
for(int z = 0; z < 4; z++)
{
dp[i][j][k][z] = -1;
}
}
}
}
cout << solve(0, 3, 3, 3)-1 << '\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... |