Submission #879441

# Submission time Handle Problem Language Result Execution time Memory
879441 2023-11-27T12:36:37 Z amin_2008 Miners (IOI07_miners) C++17
100 / 100
94 ms 201876 KB
#pragma GCC optimize ("O3")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// author: amin_2008

#define ios          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll           long long
#define vi           vector<int>
#define vs           vector<string>
#define vc           vector<char>
#define vl           vector<ll>
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define pb           push_back
#define bpc          __builtin_popcount
#define pii          pair<int, int>
#define pll          pair<ll, ll>
#define piii         pair<pii, int>
#define vpii         vector<pii>
#define vpll         vector<pll>
#define vvpii        vector<vpii>
#define vvi          vector<vector<int>>
#define vvl          vector<vector<ll>>
#define ins          insert
#define ts           to_string
#define F            first
#define S            second
#define lb           lower_bound
#define ub           upper_bound
#define ld           long double
#define ull          unsigned long long
#define endl         '\n'
#define int          ll

using namespace std;
using namespace __gnu_pbds;
using namespace __cxx11;
template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const int mod = 1e9+7;
const int sz = 3e5+5;
const int N = 100005;
const int logg = 18;
const int P = 40000005;
const int M = 5e5+5;

int a[sz];
int dp[N][4][4][4][4];

int f(int x, int y, int z)
{
    if ( x )
    {
        if ( x == y and y == z )
            return 1;
        else if ( ( x == y ) ^ ( y == z ) ^ ( z == x ) )
            return 2;
        else
            return 3;
    }
    if ( y )
    {
        if ( y == z )
            return 1;
        else
            return 2;
    }
    return 1;
}

void solve()
{
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 4; k++)
            {
                for(int l = 0; l < 4; l++)
                {
                    for(int m = 0; m < 4; m++)
                    {
                        dp[i][j][k][l][m] = -inf;
                    }
                }
            }
        }
    }
    dp[0][0][0][0][0] = 0;
    for(int i = 1; i <= n; i++)
    {
        char c;
        cin >> c;
        int x = ( c == 'M' ? 1 : ( c == 'F' ? 2 : 3 ));
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 4; k++)
            {
                for(int l = 0; l < 4; l++)
                {
                    for(int m = 0; m < 4; m++)
                    {
                        dp[i][j][x][l][m] = max(dp[i][j][x][l][m], dp[i-1][k][j][l][m] + f(k, j, x));
                    }
                }
            }
        }
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 4; k++)
            {
                for(int l = 0; l < 4; l++)
                {
                    for(int m = 0; m < 4; m++)
                    {
                        dp[i][j][k][l][x] = max(dp[i][j][k][l][x], dp[i-1][j][k][m][l] + f(m, l, x));
                    }
                }
            }
        }
    }
    int res = 0;
    for(int i = 0; i < 4; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 4; k++)
            {
                for(int l = 0; l < 4; l++)
                {
                    res = max(res, dp[n][i][j][k][l]);
                }
            }
        }
    }
    cout << res << endl;
}

signed main()
{
    ios;
    //precompute();
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 51976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 152548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 201876 KB Output is correct