Submission #672522

# Submission time Handle Problem Language Result Execution time Memory
672522 2022-12-16T13:27:05 Z sudheerays123 Miners (IOI07_miners) C++17
33 / 100
1500 ms 244524 KB
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 1e5+5 , INF = 1e18 , MOD = 1e9+7;

ll dp[N][4][4][4][4];
vector<ll> a(N);
ll n;

ll chartoll(char x){
	if(x == 'M') return 1ll;
	if(x == 'B') return 2ll;
	return 3ll;
}

ll go(ll i , ll pre1 , ll pree1 , ll pre2 , ll pree2){

	if(i == n+1) return 0;
	if(dp[i][pre1][pree1][pre2][pree2] != -1) return dp[i][pre1][pree1][pre2][pree2];
	
	set<ll> s1;
	if(pre1 != -1) s1.insert(pre1);
	if(pree1 != -1) s1.insert(pree1);
	s1.insert(a[i]);
	ll uuu = s1.size();

	ll ans = uuu+go(i+1,a[i],pre1,pre2,pree2);
	
	set<ll> s2;
	if(pre2 != -1) s2.insert(pre2);
	if(pree2 != -1) s2.insert(pree2);
	s2.insert(a[i]);
	ll uu = s2.size();

	ans = max(ans,uu+go(i+1,pre1,pree1,a[i],pre2));
	
	return dp[i][pre1][pree1][pre2][pree2] = ans;
}

void solve(){

	string s;
	cin >> n >> s;
	s = ' '+s;
	for(ll i = 1; i <= n; i++) a[i] = chartoll(s[i]);

	if(n <= 20){

		ll ans = -INF;

		for(ll i = 0; i < (1ll<<n); i++){

			vector<char> mine1,mine2;
			for(ll j = 0; j < n; j++){
				if(i&(1ll<<j)) mine1.push_back(s[j+1]);
				else mine2.push_back(s[j+1]);
			}

			ll score = 0;

			for(ll j = 0; j < mine1.size(); j++){
				set<char> food;
				for(ll k = j; k >= max(0ll,j-2); k--) food.insert(mine1[k]);
				score += food.size();
			}

			for(ll j = 0; j < mine2.size(); j++){
				set<char> food;
				food.insert(mine2[j]);
				for(ll k = j; k >= max(0ll,j-2); k--) food.insert(mine2[k]);
				score += food.size();
			}

			ans = max(ans,score);
		}

		// cout << ans;
		// return;
	}

	memset(dp,-1,sizeof dp);

	cout << go(1,-1,-1,-1,-1);
}

int main(){

	fast;

	ll tc = 1;
	// cin >> tc;
	while(tc--) solve();

	return 0;
}

Compilation message

miners.cpp: In function 'void solve()':
miners.cpp:62:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    for(ll j = 0; j < mine1.size(); j++){
      |                  ~~^~~~~~~~~~~~~~
miners.cpp:68:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |    for(ll j = 0; j < mine2.size(); j++){
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 71 ms 201420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 201436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 223 ms 201428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 916 ms 201412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1575 ms 201424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 201432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 201876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 203320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 205840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 211 ms 211348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 300 ms 222336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 711 ms 244524 KB Output isn't correct
2 Halted 0 ms 0 KB -