QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658293#7894. Many Many Headsyufaiwong5#WA 0ms3844kbC++231.2kb2024-10-19 16:34:492024-10-19 16:34:52

Judging History

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

  • [2024-10-19 16:34:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-10-19 16:34:49]
  • 提交

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;
}

详细

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]