QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617486 | #7743. Grand Finale | REN5511 | WA | 0ms | 3760kb | C++14 | 3.7kb | 2024-10-06 15:51:19 | 2024-10-06 15:51:20 |
Judging History
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];
set<pair<int, pair<int, int>>>mp[2500 + 100];
//抽一 抽二 伤口
bool check(int mid) {
for (int i = 0; i <= m; i++) {
mp[i].clear();
}
int q=0, b=0, w=0;
for (int i = 1; i <= n; i++) {
if (hand[i] == 'Q') {
q++;
}
else 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 (d1 + d2 * 2 + i > m) {
return 1;
}
}
}
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 } });
if (d1 + d2 * 2 + i > m) {
return 1;
}
}
else {
if (library[i-1] == 'Q') {
d1++;
}
else if (library[i-1] == 'B') {
d2++;
}
else {
w++;
}
mp[i].insert({ d1, { d2, w } });
if (d1 + d2 * 2 + i > m) {
return 1;
}
}
}
}
}
}
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];
}
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()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3760kb
input:
2 2 6 BG BQWBWW 4 6 GQBW WWWWQB
output:
2 IMPOSSIBLE
result:
wrong answer 1st lines differ - expected: '3', found: '2'