QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658478 | #7894. Many Many Heads | yufaiwong5# | WA | 0ms | 3756kb | C++23 | 1.8kb | 2024-10-19 16:53:14 | 2024-10-19 16:53:16 |
Judging History
answer
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
bool checkStr(string& input) {
int sC = 0, aC = 0;
for(int i=0; i<input.size(); i++) {
if(input[i] == '(' || input[i] == ')') sC++;
if(input[i] == '[' || input[i] == ']') aC++;
}
// cout << "sC " << (sC % 2) << " AC " << (aC%2) << endl;
return sC % 2 == 0 && aC % 2 == 0;
}
void fixPair(string& input, char cA, char cB) {
int pA = 0, pB = input.size() - 1;
while(pA <= pB) {
bool pAOK = input[pA] == cA || input[pA] == cB;
bool pBOK = input[pB] == cA || input[pB] == cB;
if(pAOK && pBOK) {
input[pA] = cA;
input[pB] = cB;
pA++;
pB--;
}
if(!pAOK) {
pA++;
}
if(!pBOK) {
pB--;
}
}
}
void run(string& input, unordered_set<string>& used) {
if(!checkStr(input)) {
cout << "No" << endl;
return;
}
int pA = 0, pB = input.size() - 1;
// fix the pair to perfect first.
fixPair(input, '(', ')');
fixPair(input, '[', ']');
// cout << "Fix input " << input << endl;
if(used.count(input) || input.find("((") != string::npos || input.find("[[") != string::npos || input.find(")(") != string::npos || input.find("][") != string::npos) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
used.insert(input);
}
int main()
{
int caseNum;
cin >> caseNum;
string input;
unordered_set<string> used;
getline(cin, input);
for(int i=0; i < caseNum; i++) {
getline(cin, input);
run(input, used);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3756kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes No Yes No Yes No
result:
ok 6 token(s): yes count is 3, no count is 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3520kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]