제출 #1097127

#제출 시각아이디문제언어결과실행 시간메모리
1097127vjudge1Miners (IOI07_miners)C++17
100 / 100
238 ms756 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, a) for (int i = 0; i < (a); ++i) #define REPD(i, a) for (int i = (a) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX 100005 int dp[2][4][4][4][4]; //0: not consider yet //1: fish //2: meat //3: bread int N; string s; int conv(char c){ if(c == 'F') return 1; if(c == 'M') return 2; if(c == 'B') return 3; return 0; } int cost(int a, int b, int c){ if(a * b * c == 0){ int cnt = 0; cnt += (a == 0); cnt += (b == 0); cnt += (c == 0); if(cnt == 1) return (b != c) + 1; if(cnt == 2) return 1; } if(a != b && b != c && c != a) return 3; if(a != b || b != c || c != a) return 2; return 1; } void process(void){ cin >> N >> s; memset(dp, -0x3f, sizeof dp); dp[0][0][0][0][0] = 0; REP(i, N){ memset(dp[1], -0x3f, sizeof dp[1]); REP(l_semi, 4) REP(l_last, 4) REP(r_semi, 4) REP(r_last, 4){ int v = conv(s[i]); int &ret = dp[0][l_semi][l_last][r_semi][r_last]; maximize(dp[1][l_last][v][r_semi][r_last], ret + cost(l_semi, l_last, v)); maximize(dp[1][l_semi][l_last][r_last][v], ret + cost(r_semi, r_last, v)); } swap(dp[0], dp[1]); } int ans = 0; REP(l_semi, 4) REP(l_last, 4) REP(r_semi, 4) REP(r_last, 4){ maximize(ans, dp[0][l_semi][l_last][r_semi][r_last]); } cout << ans; } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); // freopen(name".inp", "r", stdin); // freopen(name".out", "w", stdout); process(); return (0 ^ 0); }
#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...