Submission #535119

# Submission time Handle Problem Language Result Execution time Memory
535119 2022-03-09T13:06:21 Z kebine Miners (IOI07_miners) C++17
100 / 100
129 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef double dbl;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef map<ll, ll> mll;
typedef pair<string, ll> psl;
typedef map<string, ll> msl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef deque<ll> deq;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqm;
typedef priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> dij;
typedef priority_queue<ll> pq;
typedef string str;
const ll mod=1e9+9;
const ll maxn=2e5+1;
ll gcd(ll a, ll b) {
    return a==0 ? b : gcd(a, b%a);
}
ll lcm(ll a, ll b) {
    ll ans=a*b;
    ans=ans/(gcd(a, b));
    return ans;
}
#define ihacoy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dh << endl;
#define co cout <<
#define udh cout << endl;
#define spa << " ";
#define ci cin >>
#define fi first
#define se second
#define sp << " " <<
#define tes while(t--)
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define gre greater<ll>()
#define sip return 0
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
int n, nxt, now, ans;
str s;
int main() {
    ihacoy
    ci n >> s;
    int dp[2][4][4][4][4];
    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%2][j][k][l][m]<0) continue;
                        if(s[i]=='M') nxt=1;
                        else if(s[i]=='B') nxt=2;
                        else nxt=3;
                        now=1;
                        if(j && j!=nxt) now++;
                        if(k && k!=nxt && k!=j) now++;
                        dp[(i+1)%2][nxt][j][l][m]=max(dp[(i+1)%2][nxt][j][l][m], dp[i%2][j][k][l][m]+now);
                        now=1;
                        if(l && l!=nxt) now++;
                        if(m && m!=nxt && m!=l) now++;
                        dp[(i+1)%2][j][k][nxt][l]=max(dp[(i+1)%2][j][k][nxt][l], dp[i%2][j][k][l][m]+now);
                    }
                }
            }
        }
    }
    for(int i=0; i<=3; i++) {
        for(int j=0; j<=3; j++) {
            for(int k=0; k<=3; k++) {
                for(int l=0; l<=3; l++) {
                    ans=max(ans, dp[n%2][i][j][k][l]);
                }
            }
        }
    }
    co ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 600 KB Output is correct