QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265171#7743. Grand Finaleucup-team228#WA 0ms3860kbC++174.3kb2023-11-25 17:06:182023-11-25 17:06:18

Judging History

你现在查看的是最新测评结果

  • [2023-11-25 17:06:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2023-11-25 17:06:18]
  • 提交

answer

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <random>
#include <string>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <bitset>
#include <array>
#include <stack>
#include <sstream>

using namespace std;
typedef long long ll;
 
string to_string(string a) { return '"' + a + '"'; }
string to_string(char a) { return "'" + string(1, a) + "'"; }
string to_string(const char* a) { return to_string((string) a); }
string to_string(bool a) { return a ? "true" : "false"; }
template <class T1, class T2>
string to_string(pair<T1, T2> a) {
    return "(" + to_string(a.first) + ", " + to_string(a.second) + ")";
}
template <class T>
string to_string(T a) {
    bool first = true; string res = "{";
    for (const auto& i : a) {
        if (!first) res += ", ";
        first = false;
        res += to_string(i);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <class T1, class... T2>
void debug_out(T1 a, T2... b) {
    cerr << " " << to_string(a);
    debug_out(b...);
}
 
#ifdef LOCAL
#define out(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define out(...) 42
#endif

clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double) (clock() - start_time) / CLOCKS_PER_SEC; }

void Solve();

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
    start_timer();
    Solve();
#ifdef LOCAL
    cerr << fixed << setprecision(3);
    cerr << endl << "Time spent: " << get_time() << endl;
#endif
    return 0;
}

// do something, stay focused
// look for stupid bugs
// guess, slow, stress
// don't overgeneralize
// don't rush

// don't waste time on standings

// SOLVE THE PROBLEM OR DIE TRYING
// THE SOLUTION IS ALWAYS SIMPLE
// THE CODE IS ALWAYS SHORT

string tr(string s) {
    string res;
    for (char c : s) {
        if (c == 'G' || c == 'W') {
            res += '0';
        }
        else if (c == 'Q') {
            res += '1';
        }
        else {
            res += '2';
        }
    }
    return res;
}

void Solve() {
    int T;
    cin >> T;
    while (T--) {
        int n, m;
        cin >> n >> m;
        string s, t;
        cin >> s >> t;
        s = tr(s);
        t = tr(t);
        reverse(t.begin(), t.end());
        int l = n;
        int r = n + m + 1;
        while (l < r) {
            int k = (l + r) / 2;
            int cnt[3] = {};
            for (char c : s) {
                cnt[c - '0']++;
            }
            string x = t;
            while (1) {
                if (x.empty()) break;
                //out(cnt[0], cnt[1], cnt[2]);
                if (cnt[2] && x.size() >= 2 && x[x.size() - 2] == '0') {
                    cnt[2]--;
                    for (int i = 1; i <= 2; i++) {
                        //if (x.empty()) break;
                        char c = x.back();
                        x.pop_back();
                        if (cnt[0] + cnt[1] + cnt[2] < k) {
                            cnt[c - '0']++;
                        }
                    }
                }
                else if (cnt[1]) {
                    cnt[1]--;
                    char c = x.back();
                    x.pop_back();
                    cnt[c - '0']++;
                }
                else if (cnt[2]) {
                    cnt[2]--;
                    for (int i = 1; i <= 2; i++) {
                        if (x.empty()) break;
                        char c = x.back();
                        x.pop_back();
                        if (cnt[0] + cnt[1] + cnt[2] < k) {
                            cnt[c - '0']++;
                        }
                    }
                }
                else break;
            }
            if (x.empty()) {
                r = k;
            }
            else {
                l = k + 1;
            }
        }
        if (l == n + m + 1) {
            cout << "IMPOSSIBLE\n";
        }
        else {
            cout << l << "\n";
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3860kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

4
4

result:

wrong answer 1st lines differ - expected: '3', found: '4'