Submission #213507

# Submission time Handle Problem Language Result Execution time Memory
213507 2020-03-26T03:28:28 Z tatyam Miners (IOI07_miners) C++17
100 / 100
434 ms 632 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
#define all(a) begin(a), end(a)
#define each(i,a) for(auto&& i : a)
#define rep(n) for(int i = 0; i < (n); ++i)
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
 
inline constexpr int kinds(int a, int b, int c){
    if(a > b) swap(a, b);
    if(b > c) swap(b, c);
    if(a > b) swap(a, b);
    int ans = 3;
    if(!a || a == b) ans--;
    if(!b || b == c) ans--;
    return ans;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s >> s;
    each(i, s){
        if(i == 'B') i = 1;
        else if(i == 'F') i = 2;
        else i = 3;
    }
    vector<int> dp1(1 << 8, -INF);
    dp1[0] = 0;
    each(c, s){
        vector<int> dp2(1 << 8, -INF);
        rep(1 << 8){
            int a1 = i >> 6 & 3, a2 = i >> 4 & 3, b1 = i >> 2 & 3, b2 = i & 3;
            int j = a2 << 6 | c << 4 | b1 << 2 | b2;
            chmax(dp2[j], dp1[i] + kinds(a1, a2, c));
            j = a1 << 6 | a2 << 4 | b2 << 2 | c;
            chmax(dp2[j], dp1[i] + kinds(b1, b2, c));
        }
        swap(dp1, dp2);
    }
    cout << *max_element(all(dp1)) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 434 ms 632 KB Output is correct