QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617351#7743. Grand FinaleREN5511TL 0ms3572kbC++143.4kb2024-10-06 15:04:582024-10-06 15:04:58

Judging History

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

  • [2024-10-06 15:04:58]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3572kb
  • [2024-10-06 15:04:58]
  • 提交

answer

#include <iostream>
#include <unordered_map>
#include <set>
using namespace std;
typedef long long ll;
int n, m;
int iniq = 0, inib = 0;
char hand[2500 + 100], library[2500 + 100];
unordered_map<ll, set<pair<ll, pair<ll, ll>>>>mp;
//抽一 抽二 伤口
bool check(int mid) {
    mp.clear();
    int q=0, b=0, w=0;
    for (int i = 1; i <= n; i++) {
        if (hand[i] == 'Q') {
            q++;
        }
        if (hand[i] == 'B') {
            b++;
        }
        else {
            w++;
        }
    }
    mp[0].insert({q, { b, w }});
    for (int i = 1; i <= m; i++) {
        if (mp[m].size())return 1;
        for (auto h : mp[i - 1]) {
            int d1 = h.first, d2 = h.second.first, w = h.second.second;
            if (d1 > 0) {
                d1--;
                if (library[i] == 'Q') {
                    d1++;
                }
                else if (library[i] == 'B') {
                    d2++;
                }
                else {
                    w++;
                }
                mp[i].insert({ d1, { d2, w } });
            }
        }
        if (i > 1) {
            for (auto h : mp[i - 2]) {
                int d1 = h.first, d2 = h.second.first, w = h.second.second;
                if (d2 > 0) {
                    d2--;
                    if (d1 + d2 + w < mid) {
                        if (library[i-1] == 'Q') {
                            d1++;
                        }
                        else if (library[i-1] == 'B') {
                            d2++;
                        }
                        else {
                            w++;
                        }
                        if (library[i] == 'Q') {
                            d1++;
                        }
                        else if (library[i] == 'B') {
                            d2++;
                        }
                        else {
                            w++;
                        }
                        mp[i].insert({ d1, { d2, w } });
                    }
                    else {
                        if (library[i-1] == 'Q') {
                            d1++;
                        }
                        else if (library[i-1] == 'B') {
                            d2++;
                        }
                        else {
                            w++;
                        }
                        mp[i].insert({ d1, { d2, w } });
                    }
                }
            }
        }

    }
    if (mp[m].size())return 1;
    return 0;
}
int findans(int l, int r) {
    int ans = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid)) {
            ans = mid;
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    return ans;
}
void solve() {
    iniq = 0; inib = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> hand[i];
        if (hand[i] == 'Q') {
            iniq++;
        }
        if (hand[i] == 'B') {
            inib++;
        }
    }
    for (int i = 1; i <= m; i++) {
        cin >> library[i];
    }
    int ans = findans(n, 3000);
    if (ans == -1) {
        cout << "IMPOSSIBLE" << "\n";
    }
    else {
        cout << ans << "\n";
    }
}
int main()
{
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

2
2 6
BG
BQWBWW
4 6
GQBW
WWWWQB

output:

3
IMPOSSIBLE

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

2
3 8
QBG
BBBWBWWW
3 8
QBG
BBBWBWWW

output:

3
3

result:

ok 2 lines

Test #3:

score: -100
Time Limit Exceeded

input:

13
184 887
WBQBBWWBQBQBQBWWBBQQWWQQQBBBQWWWQWBBBBWWWQQBQQQWQBBQQWQQBBWWQWQQBWBQWWWWQWQQWQBWWQQWWQQBWWQWBBBWWQWBQBQWQQWWBQBQQBWQBQBWWBWQWQWBWBQWWQBQQQBWQQWQWWBQBWWQQBQWBQQBQQBQBBQBWBQQWWQBWBBQQBQG
QWBQBQBWBQQWWWWQBBBQQQBBBWWWWQWQWWQQQBQBWQQQBWQWQBWWBQQQWQWBQBBQBWBBWBQWQBWWQQBWQQWWQWWQQWBQQWQWBBQBWBQQ...

output:


result: