QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617462 | #7743. Grand Finale | Dukerki | Compile Error | / | / | C++23 | 7.3kb | 2024-10-06 15:40:35 | 2024-10-06 15:40:35 |
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];
unordered_map<int, set<pair<int, pair<int, int>>>>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 (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;
}#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<int, set<pair<int, pair<int, int>>>>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 (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
answer.code:140:2: error: stray ‘#’ in program 140 | }#include <iostream> | ^ answer.code:140:3: error: ‘include’ does not name a type 140 | }#include <iostream> | ^~~~~~~ answer.code:145:5: error: redefinition of ‘int n’ 145 | int n, m; | ^ answer.code:6:5: note: ‘int n’ previously declared here 6 | int n, m; | ^ answer.code:145:8: error: redefinition of ‘int m’ 145 | int n, m; | ^ answer.code:6:8: note: ‘int m’ previously declared here 6 | int n, m; | ^ answer.code:146:5: error: redefinition of ‘int iniq’ 146 | int iniq = 0, inib = 0; | ^~~~ answer.code:7:5: note: ‘int iniq’ previously defined here 7 | int iniq = 0, inib = 0; | ^~~~ answer.code:146:15: error: redefinition of ‘int inib’ 146 | int iniq = 0, inib = 0; | ^~~~ answer.code:7:15: note: ‘int inib’ previously defined here 7 | int iniq = 0, inib = 0; | ^~~~ answer.code:147:6: error: redefinition of ‘char hand [2600]’ 147 | char hand[2500 + 100], library[2500 + 100]; | ^~~~ answer.code:8:6: note: ‘char hand [2600]’ previously declared here 8 | char hand[2500 + 100], library[2500 + 100]; | ^~~~ answer.code:147:24: error: redefinition of ‘char library [2600]’ 147 | char hand[2500 + 100], library[2500 + 100]; | ^~~~~~~ answer.code:8:24: note: ‘char library [2600]’ previously declared here 8 | char hand[2500 + 100], library[2500 + 100]; | ^~~~~~~ answer.code:148:51: error: redefinition of ‘std::unordered_map<int, std::set<std::pair<int, std::pair<int, int> > > > mp’ 148 | unordered_map<int, set<pair<int, pair<int, int>>>>mp; | ^~ answer.code:9:51: note: ‘std::unordered_map<int, std::set<std::pair<int, std::pair<int, int> > > > mp’ previously declared here 9 | unordered_map<int, set<pair<int, pair<int, int>>>>mp; | ^~ answer.code:150:6: error: redefinition of ‘bool check(int)’ 150 | bool check(int mid) { | ^~~~~ answer.code:11:6: note: ‘bool check(int)’ previously defined here 11 | bool check(int mid) { | ^~~~~ answer.code:238:5: error: redefinition of ‘int findans(int, int)’ 238 | int findans(int l, int r) { | ^~~~~~~ answer.code:99:5: note: ‘int findans(int, int)’ previously defined here 99 | int findans(int l, int r) { | ^~~~~~~ answer.code:252:6: error: redefinition of ‘void solve()’ 252 | void solve() { | ^~~~~ answer.code:113:6: note: ‘void solve()’ previously defined here 113 | void solve() { | ^~~~~ answer.code:269:5: error: redefinition of ‘int main()’ 269 | int main() | ^~~~ answer.code:130:5: note: ‘int main()’ previously defined here 130 | int main() | ^~~~