Submission #473863

# Submission time Handle Problem Language Result Execution time Memory
473863 2021-09-16T10:53:28 Z dxz05 Miners (IOI07_miners) C++14
100 / 100
141 ms 384 KB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e5 + 3e2;
const int M = 522;

int f(char c){
    return (c == 'M' ? 0 : c == 'F' ? 1 : 2);
}

void chmax(int &a, int b){
    a = max(a, b);
}

int last, diff = 0;
void add(int k, int x){
    if (k == 0){
        last = x + 1;
        diff = 1;
        return;
    }

    if (k < 4){
        k = (k - 1) * 3 + x;
        last = k + 4;
        diff = 1 + (k / 3 != k % 3);
        return;
    }

    k -= 4;
    int a = k / 3;

    k %= 3;
    k = k * 3 + x;

    last = k + 4;
    int b = k / 3, c = k % 3;
    if (a == b && b == c) diff = 1; else
    if (a != b && a != c && b != c) diff = 3; else
        diff = 2;
}

int dp[2][13][13];
char s[N];
void solve(int TC) {
    int n;
    scanf("%d %s", &n, &s);

    for (int i = 0; i < 2; i++){
        for (int j = 0; j < 13; j++){
            for (int k = 0; k < 13; k++){
                dp[i][j][k] = -20;
            }
        }
    }

    int f0 = f(s[0]);
    dp[0][f0 + 1][0] = dp[0][0][f0 + 1] = 1;

    for (int i = 0; i < n - 1; i++){
        int c = f(s[i + 1]);

        int cur = 0;
        for (int x = 0; x < 13; x++){
            for (int y = 0; y < 13; y++){
                cur = max(cur, dp[i % 2][x][y]);
//                cout << dp[i % 2][x][y] << ' ';
                int a = x, b = y;

                add(a, c);
                chmax(dp[1 - i % 2][last][y], dp[i % 2][x][y] + diff);

                add(b, c);
                chmax(dp[1 - i % 2][x][last], dp[i % 2][x][y] + diff);
            }
//            cout << endl;
        }
//        cout << endl;

        debug(i, cur);

    }

    int ans = 0;

    for (int i = 0; i < 13; i++){
        for (int j = 0; j < 13; j++){
            ans = max(ans, dp[(n - 1) % 2][i][j]);
        }
    }

    cout << ans;

}

int main() {
    startTime = clock();
    //ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
//    cin >> TC;

    for (int test = 1; test <= TC; test++) {
        debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    //cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}

Compilation message

miners.cpp: In function 'void solve(int)':
miners.cpp:83:16: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[200300]' [-Wformat=]
   83 |     scanf("%d %s", &n, &s);
      |               ~^       ~~
      |                |       |
      |                char*   char (*)[200300]
miners.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
miners.cpp:116:9: note: in expansion of macro 'debug'
  116 |         debug(i, cur);
      |         ^~~~~
miners.cpp: In function 'int main()':
miners.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
miners.cpp:145:9: note: in expansion of macro 'debug'
  145 |         debug(test);
      |         ^~~~~
miners.cpp: In function 'void solve(int)':
miners.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     scanf("%d %s", &n, &s);
      |     ~~~~~^~~~~~~~~~~~~~~~~
# 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 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 0 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 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 384 KB Output is correct