QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363225#7894. Many Many HeadsOobugoOWA 16ms3744kbC++201.0kb2024-03-23 19:40:142024-03-23 19:40:14

Judging History

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

  • [2024-03-23 19:40:14]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3744kb
  • [2024-03-23 19:40:14]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second

typedef long long ll;

int get(char c) {
    if (c == '#')   return 0x3f3f3f3f;
    return c == '(' || c == ')';
}

void solve() {
    std::string s;
    std::cin >> s;
    char pre = '#';
    int num = 0;
    std::vector<char> st(1, '#');    
    for (auto x : s) {
        if (get(x) == get(st.back())) 
            st.pop_back();
        else
            st.push_back(x);
        if (st.size() == 1) {
            num++;
            if (get(pre) == get(x) || num > 2) {
                std::cout << "No\n";
                return;
            }
            pre = x;
        }
    }
    if (st.size() == 1) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
}

int main(){

#ifdef Onlion_Judge
    freopen("IO/input.in", "r", stdin);
    freopen("IO/output.out", "w", stdout);
    // freopen("E:\\save work\\data\\4.in", "w", stdout);
#endif

    int t = 1;
    std::cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 1ms
memory: 3412kb

input:

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

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: -100
Wrong Answer
time: 16ms
memory: 3592kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
Yes
No
Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No...

result:

wrong answer expected NO, found YES [45th token]