Submission #672447

# Submission time Handle Problem Language Result Execution time Memory
672447 2022-12-16T09:05:51 Z sudheerays123 Miners (IOI07_miners) C++17
52 / 100
1488 ms 212624 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][(1ll<<(4))][(1ll<<(4))];
ll n;
string s;
vector<ll> mine1,mine2;

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

ll go(ll i , ll mask1 , ll mask2){

	if(i == n+1) return 0;
	if(dp[i][mask1][mask2] != -1) return dp[i][mask1][mask2];

	ll ans = 0;

	ll curmask1 = mask1;
	curmask1 |= (1ll<<(chartoll(s[i])));
	ll c1 = __builtin_popcount(curmask1);

	ll newmask1 = (1ll<<(chartoll(s[i])));
	if(mine1.size() >= 1){
		ll x = mine1[mine1.size()-1];
		newmask1 |= (1ll<<x);
	}
	mine1.push_back(chartoll(s[i]));
	ans = max(ans,c1+go(i+1,newmask1,mask2));
	mine1.pop_back();

	ll curmask2 = mask2;
	curmask2 |= (1ll<<(chartoll(s[i])));
	ll c2 = __builtin_popcount(curmask2);

	ll newmask2 = (1ll<<(chartoll(s[i])));
	if(mine2.size() >= 1){
		ll x = mine2[mine2.size()-1];
		newmask2 |= (1ll<<x);
	}
	mine2.push_back(chartoll(s[i]));
	ans = max(ans,c2+go(i+1,mask1,newmask2));
	mine2.pop_back();

	return dp[i][mask1][mask2] = ans;
}

void solve(){

	cin >> n >> s;
	s = ' '+s;

	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,0,0);
}

int main(){

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

	return 0;
}

Compilation message

miners.cpp: In function 'void solve()':
miners.cpp:73:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for(ll j = 0; j < mine1.size(); j++){
      |                  ~~^~~~~~~~~~~~~~
miners.cpp:79:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |    for(ll j = 0; j < mine2.size(); j++){
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 839 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1488 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 200684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 200740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 201272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 201932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 203656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 113 ms 209916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 137 ms 212624 KB Output isn't correct
2 Halted 0 ms 0 KB -