QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658293 | #7894. Many Many Heads | yufaiwong5# | WA | 0ms | 3844kb | C++23 | 1.2kb | 2024-10-19 16:34:49 | 2024-10-19 16:34:52 |
Judging History
answer
#include <iostream>
#include <string>
using namespace std;
// 1st scan: ()() <--- not gonna work, as it can become (())
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) {
int pA = 0, pB = input.size() - 1;
// fix the pair to perfect first.
fixPair(input, '(', ')');
fixPair(input, '[', ']');
// cout << "Fix input " << input << endl;
if(input.find("((") != string::npos || input.find("[[") != string::npos) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
int main()
{
int caseNum;
cin >> caseNum;
string input;
getline(cin, input);
for(int i=0; i < caseNum; i++) {
getline(cin, input);
run(input);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3844kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]