이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Problem: IOI 2007 Miners
When: 2023-11-13 21:27:07
Author: JN
*/
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)
#define all(x) x.begin(), x.end()
int dp[500][4][4][4][4];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin>>n;
string s; cin>>s;
vector<int> a(n+1);
L(i,0,n-1){
if(s[i]=='M') a[i]=1;
if(s[i]=='B') a[i]=2;
if(s[i]=='F') a[i]=3;
}
memset(dp,-1,sizeof(dp));
dp[0][0][0][0][0]=0;
auto profit=[&](int x,int y,int z){
set<int> s; s.insert(x); s.insert(y); s.insert(z);
int cnt=s.size();
if(*s.begin()==0) cnt--;
return cnt;
};
L(i,0,n-1){
int nw=i&1,nx=nw^1;
L(a1,0,3) L(a2,0,3) L(b1,0,3) L(b2,0,3){
if(dp[nw][a1][a2][b1][b2]==-1) continue;
dp[nx][a2][a[i]][b1][b2]=max(dp[nx][a2][a[i]][b1][b2], dp[nw][a1][a2][b1][b2]+profit(a1,a2,a[i]));
dp[nx][a1][a2][b2][a[i]]=max(dp[nx][a1][a2][b2][a[i]], dp[nw][a1][a2][b1][b2]+profit(b1,b2,a[i]));
// cout<<a1<<' '<<a2<<' '<<b1<<' '<<b2<<' ';
// cout<<profit(a1,a2,a[i])<<' ';
// cout<<profit(b1,b2,a[i])<<'\n';
}
}
int ans=0,nw=n&1;
L(a1,0,3) L(a2,0,3) L(b1,0,3) L(b2,0,3){
if(ans<dp[nw][a1][a2][b1][b2]){
ans=dp[nw][a1][a2][b1][b2];
}
}
cout<<ans<<'\n';
}
# | 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... |