Submission #672508

# Submission time Handle Problem Language Result Execution time Memory
672508 2022-12-16T11:17:37 Z sudheerays123 Miners (IOI07_miners) C++17
25 / 100
1500 ms 88984 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][10][10];
vector<ll> a(N);
ll n;

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

ll score(ll mask , ll dig){
	mask = mask|(1ll<<dig);
	ll x = __builtin_popcountll(mask);
	return x;
}

ll newmask(ll dig , ll pre){
	ll y = (1ll<<dig);
	if(pre != -1) y = y|(1ll<<pre);
	return y;
}

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

	if(i == n+1) return 0;
	if(dp[i][mask1][mask2] != -1) return dp[i][mask1][mask2];
	
	ll ans = score(mask1,a[i])+go(i+1,newmask(a[i],pre1),mask2,a[i],pre2);
	ans = max(ans,score(mask2,a[i])+go(i+1,mask1,newmask(a[i],pre2),pre1,a[i]));
	
	return dp[i][mask1][mask2] = 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,0,0,-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:61:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    for(ll j = 0; j < mine1.size(); j++){
      |                  ~~^~~~~~~~~~~~~~
miners.cpp:67:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for(ll j = 0; j < mine2.size(); j++){
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 79308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 79312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 79312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 875 ms 79316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1524 ms 79312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 79316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 79448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 79828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 80252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 81740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 86508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 88984 KB Output isn't correct
2 Halted 0 ms 0 KB -