제출 #1156254

#제출 시각아이디문제언어결과실행 시간메모리
1156254Alihan_8Miners (IOI07_miners)C++20
100 / 100
377 ms636 KiB
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e8;

int pw[5] = {1, 4, 16, 64, 256};

void chmax(int &x, const int &y){ x = max(x, y); }

signed main(){
	int n; cin >> n;
	
	string s; cin >> s;
	
	for ( auto &x: s ){
		if ( x == 'M' ) x = 0;
		else if ( x == 'F' ) x = 1;
		else x = 2;
	}
	
	auto get = [&](int x, int y, int z){
		set <int> st;
		
		for ( auto i: {x, y, z} ){
			if ( i < 3 ) st.insert(i);
		}
		
		return st.size();
	};
	
	vector <int> dp(256, -inf);
	
	dp[255] = 0;
	
	for ( auto &v: s ){
		vector <int> nxt(256, -inf);
		
		for ( int i = 0; i < 256; i++ ){
			if ( dp[i] < 0 ) continue;
			
			{
				int x = i / pw[0] % 4, y = i / pw[1] % 4;
				 
				chmax(nxt[i - x - y * pw[1] + y + v * pw[1]], dp[i] + get(x, y, v));
			}
			{
				int x = i / pw[2] % 4, y = i / pw[3] % 4;
				
				chmax(nxt[i - x * pw[2] - y * pw[3] + y * pw[2] + v * pw[3]], dp[i] + get(x, y, v));
			}
		}
		
		swap(dp, nxt);
	}
	
	cout << *max_element(dp.begin(), dp.end()) << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...