Submission #1166845

#TimeUsernameProblemLanguageResultExecution timeMemory
1166845maxphastMiners (IOI07_miners)C++20
100 / 100
172 ms201628 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <ll , ll> ii;
typedef pair <ll , ii> iii;
typedef pair <ii , ii> iiii;

#define fu(i,a,n) for(ll i = a ; i <= n ; i ++)
#define fd(i,a,n) for(ll i = a ; i >= n ; i --)
#define rep(it , a) for(auto &it : a)
#define bit(i , j) ((i >> j) & 1ll)
#define turn(i , j) (i ^ (1ll << j))
#define on(i , j) (i | (1ll << j))
#define off(i , j) (i & ~(1ll << j))
#define __lcm(a , b) ((1ll * a * b) / __gcd(a , b))
#define bit1(x) __builtin_popcountll(x)
#define sqr(x) ((x) * (x))
#define oo 1e18
#define fi first
#define se second
#define TASK "test"

template <class X , class Y>
    bool maxz(X &a , const Y b)
    {
        if(a < b)
        {
            a = b;
            return true;
        }
        return false;
    }
template <class X , class Y>
    bool minz(X &a , const Y b)
    {
        if(a > b)
        {
            a = b;
            return true;
        }
    return false;
}

namespace MaxPhast
{

    const ll N = 2e5 + 5;

    ll n , ans;
    ll a[N] , dp[N][4][4][4][4];

    ll cost(ll a , ll b , ll c)
    {
        ll mask = (1 << a) | (1 << b) | (1 << c);
        return bit1(off(mask , 0));
    }

    void solve()
    {
        cin >> n;

        fu(i , 1 , n)
        {
            char c ; cin >> c;
            if(c == 'M')
                a[i] = 1;
            else
            if(c == 'F')
                a[i] = 2;
            else
                a[i] = 3;
        }

        fu(i , 0 , n)
            fu(x1 , 0 , 3)
                fu(x2 , 0 , 3)
                    fu(y1 , 0 , 3)
                        fu(y2 , 0 , 3)
                            dp[i][x1][x2][y1][y2] = -oo;

        dp[0][0][0][0][0] = 0;

        fu(i , 1 , n)
        {
            ll mask = (1 << a[i]);
            fu(x1 , 0 , 3)
            {
                fu(x2 , 0 , 3)
                {
                    fu(y1 , 0 , 3)
                    {
                        fu(y2 , 0 , 3)
                        {
                            maxz(dp[i][x1][a[i]][y2][y1] , dp[i-1][x2][x1][y2][y1] + cost(x2 , x1 , a[i]));
                            maxz(dp[i][x2][x1][y1][a[i]] , dp[i-1][x2][x1][y2][y1] + cost(y2 , y1 , a[i]));
                        }
                    }
                }
            }
        }

        fu(x1 , 0 , 3)
            fu(x2 , 0 , 3)
                fu(y1 , 0 , 3)
                    fu(y2 , 0 , 3)
                        maxz(ans , dp[n][x1][x2][y1][y2]);

        cout << ans;
    }

}

signed main(){
    ios :: sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr);
    if(fopen(TASK".INP" , "r"))
    {
        freopen(TASK".INP","r",stdin);
        //freopen(TASK".OUT","w",stdout);
    }

    MaxPhast :: solve();
}

Compilation message (stderr)

miners.cpp: In function 'int main()':
miners.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         freopen(TASK".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...