답안 #978155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978155 2024-05-09T00:47:15 Z phoenix0423 Miners (IOI07_miners) C++17
100 / 100
37 ms 608 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, ll> pdl;
typedef pair<ll, double> pld;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back 
#define f first
#define s second
// #define int long long
#define lowbit(x) x&-x
const int maxn = 1e3 + 5;
const int INF = 1e9;
map<char, int> mp = {{'M', 1}, {'F', 2}, {'B', 3}};
int dp[4][4][4][4], ndp[4][4][4][4];

int sol(int a, int b, int c){
	if(a == 0){
		if(b == 0) return 1;
		return 2 - (b == c);
	}
	return 3 - (a == c) - (b == c) - (a == b) + (a == c && b == c);
}

signed main(void){
	fastio;
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i = 0; i <= 3; i++){
		for(int j = 0; j <= 3; j++){
			for(int k = 0; k <= 3; k++){
				for(int l = 0; l <= 3; l++){
					dp[i][j][k][l] = -INF;
				}
			}
		}
	}
	dp[0][0][0][0] = 0;
	for(auto x : s){
		for(int i = 0; i <= 3; i++){
			for(int j = 0; j <= 3; j++){
				for(int k = 0; k <= 3; k++){
					for(int l = 0; l <= 3; l++){
						ndp[i][j][k][l] = -INF;
					}
				}
			}
		}
		int c = mp[x];
		for(int i = 0; i <= 3; i++){
			for(int j = 0; j <= 3; j++){
				for(int k = 0; k <= 3; k++){
					for(int l = 0; l <= 3; l++){
						ndp[i][j][l][c] = max(ndp[i][j][l][c], dp[i][j][k][l] + sol(k, l, c));
					}
				}
			}
		}
		for(int j = 0; j <= 3; j++){
			for(int k = 0; k <= 3; k++){
				for(int l = 0; l <= 3; l++){
					for(int i = 0; i <= 3; i++){
						ndp[j][c][k][l] = max(ndp[j][c][k][l], dp[i][j][k][l] + sol(i, j, c));
					}
				}
			}
		}
		swap(dp, ndp);
	}
	int ans = 0;
	for(int i = 0; i <= 3; i++){
		for(int j = 0; j <= 3; j++){
			for(int k = 0; k <= 3; k++){
				for(int l = 0; l <= 3; l++){
					ans = max(ans, dp[i][j][k][l]);
				}
			}
		}
	}
	cout<<ans<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 608 KB Output is correct