QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658373#7894. Many Many Headsyufaiwong5#WA 0ms3592kbC++231.4kb2024-10-19 16:43:492024-10-19 16:43:49

Judging History

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

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

answer

#include <iostream>
#include <string>
#include <unordered_set>

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, unordered_set<string>& used) {
    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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

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: 3592kb

input:

2
(([([[([
]]))])]])]

output:

No
No

result:

wrong answer expected YES, found NO [1st token]