QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755115#7894. Many Many Headsyumz#RE 0ms3644kbC++231.3kb2024-11-16 16:29:482024-11-16 16:29:49

Judging History

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

  • [2024-11-16 16:29:49]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3644kb
  • [2024-11-16 16:29:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int a[100010];
vector<pair<int,int>>ans;
stack<int>q;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while( t-- ){
        ans.clear();
        string s;
        cin >> s;
        int n = s.length();
        s = " "+s;
        for(int i = 1;i <= n; ++i){
            if( s[i] == '(' || s[i] == ')' )a[i] = 0;
            else a[i] = 1;
        }
        q.push(1);
        for(int i = 2;i <= n; ++i){
            int f;
            if( !q.empty() )f = q.top(),q.pop();
            if( a[f] != a[i] )q.push(f),q.push(i);
            else if( q.size() == 0 )ans.push_back({f,i});
        }

        int bj = 1;
        for(int i = 0;i < ans.size(); ++i){
            for(int j = ans[i].first,k = ans[i].second;j+1 <= k-1; ++j,k--){
                if(a[j] == a[j+1])bj = 0;
            }
//            for(int j = ans[i].first;j <= ans[i].second; ++j){
//                cout << a[j] ;
//            }
//            cout << endl;
        }
        for(int i = 0;i < ans.size()-1; ++i){
            int x = ans[i].second,y = ans[i+1].first;
            if( a[x] == a[y] )bj = 0;
        }
        if( bj )cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3560kb

input:

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

output:

Yes
No

result:

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

Test #3:

score: -100
Runtime Error

input:

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

output:


result: