/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In lambda function:
foo.cc:31:17: error: 'ranges' has not been declared
   31 |         int b = ranges::count(tmp, 'B'), ret = 0;
      |                 ^~~~~~
foo.cc:33:32: error: 'ret' was not declared in this scope; did you mean 'rem'?
   33 |             if (tmp[i] == 'A') ret += b;
      |                                ^~~
      |                                rem
foo.cc:38:16: error: 'ret' was not declared in this scope; did you mean 'rem'?
   38 |         return ret;
      |                ^~~
      |                rem

Code

#ifndef LOCAL
#include <bits/stdc++.h>
#define debug(...)
#endif

using namespace std;
#define int long long
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';

void shelby() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> id;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '?') {
            id.push_back(i);
            if (id.size() == k) break;
        }
    }
    auto calc = [&](int x)-> int {
        string tmp = s;
        for (int i = 0; i < (x == id.size() ? (id.empty() ? n : id.back() + 1) : id[x]); ++i) {
            if (tmp[i] == '?') tmp[i] = 'A';
        }
        int rem = k - x;
        for (int i = n - 1; i >= 0 && rem; --i) {
            if (tmp[i] == '?') tmp[i] = 'B', rem--;
        }
        int b = ranges::count(tmp, 'B'), ret = 0;
        for (int i = 0; i < n; ++i) {
            if (tmp[i] == 'A') ret += b;
            else if (tmp[i] == 'B') b--;
        }
        debug(tmp, ret);

        return ret;
    };
    debug(id);
    int l = 0, r = id.size(), ans = 0;
    while (l <= r) {
        int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
        int calc1 = calc(m1), calc2 = calc(m2);
        if (calc1 >= calc2) ans = max(ans, calc1), r = m2 - 1;
        else ans = max(ans, calc2), l = m1 + 1;
    }
    cout << ans << '\n';
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case " << _ << ": ";
        shelby();
    }
}

Information

Submit By
Type
Submission
Problem
P1110 Subsequence of AB
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-06 17:22:36
Judged At
2024-11-11 02:24:20
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes