Submission #449614

# Submission time Handle Problem Language Result Execution time Memory
449614 2021-08-02T07:27:24 Z joshjms Miners (IOI07_miners) C++14
0 / 100
233 ms 524292 KB
#include <bits/stdc++.h>
 
#define KON using
#define AQUA namespace std;
 
KON AQUA
 
#define ll long long
#define int long long
#define pb push_back
#define fi first
#define se second
#define INIT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define debug(x) cout << #x << " => " << x << "\n";
#define sp " "
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
const int inf = 0x3f3f3f3f;
const int INFF = 1e18 + 5;
const int INF = 1e10 + 5;
const int MX = 3e5 + 5;
const int MXL = 105;
const int mod = 1e9 + 7;
const double ERROR = 1e-5;

int n, dp[MX][4][4][4][4];
string s;

void solve(){
	cin >> n >> s;
	memset(dp, -1, sizeof(dp));

	dp[0][0][0][0][0] = 0;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <= 3; j++){
			for(int k = 0; k <= 3; k++){
				for(int l = 0; l <= 3; l++){
					for(int m = 0; m <= 3; m++){
						if(dp[i][j][k][l][m] == -1) continue;

						int next = (s[i] == 'M' ? 1 : s[i] == 'F' ? 2 : 3);

						set <int> s1, s2;

						s1.insert(next);
						if(j) s1.insert(j);
						if(k) s1.insert(k);

						dp[i + 1][next][j][l][m] = max(dp[i + 1][next][j][l][m], dp[i][j][k][l][m] + (int) s1.size());

						s2.insert(next);
						if(l) s2.insert(l);
						if(m) s2.insert(m);
						dp[i + 1][j][k][next][l] = max(dp[i + 1][j][k][next][l], dp[i][j][k][l][m] + (int) s2.size());
					}
				}
			}
		}
	}
	int ans = 0;
	for(int j = 0; j <= 3; j++){
		for(int k = 0; k <= 3; k++){
			for(int l = 0; l <= 3; l++){
				for(int m = 0; m <= 3; m++){
					ans = max(ans, dp[n][j][k][l][m]);
				}
			}
		}
	}
	cout << ans << "\n";
}

int32_t main(){
	INIT;
	solve();
}
# Verdict Execution time Memory Grader output
1 Runtime error 218 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 222 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 220 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 212 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 206 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 222 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 219 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 214 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 225 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 233 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 227 ms 524292 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 231 ms 524292 KB Execution killed with signal 9