QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716851#7894. Many Many HeadsshuanglinWA 9ms5852kbC++143.3kb2024-11-06 16:10:392024-11-06 16:10:39

Judging History

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

  • [2024-11-06 16:10:39]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:5852kb
  • [2024-11-06 16:10:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x)  ((x) & - (x))
using PII = pair<int, int>;
using PIII = tuple<int, int, int>;
const int MOD = 1e9 + 7;
inline int mypow(int n, int k, int p = MOD) {
	int r = 1;
	for (; k; k >>= 1, n = n * n % p) {
		if (k & 1) r = r * n % p;
	}
	return r;
}
struct cmp {  //priority_queue
	bool operator()(const PIII& a, const PIII& b) {
		return std::get<0>(a) < std::get<0>(b); //down
	}
};

bool cmpsort(const PII& a, const PII& b) {  //sort
	return a.first < b.first; //up
}
int n;
string str;
int ans[1000010]={0};
deque< pair<int,char> >e;
int flag[1000010]={0};
inline void solve() {
    cin>>str;
    str=" "+str;
    n=str.size();
    for(int i=1;i<str.size();i++){
        if(e.empty()){
            e.push_back(make_pair(i,str[i]));
            continue;
        }
        if(str[i]=='('||str[i]==')'){
            if(e.back().second=='['){
                e.push_back(make_pair(i,'('));
            }
            else{
                ans[e.back().first]=i;
                e.pop_back();
            }
        }
        else{
            if(e.back().second=='('){
                e.push_back(make_pair(i,'['));
            }
            else{
                ans[e.back().first]=i;
                e.pop_back();
            }
        }
    }
    // for(int i=1;i<str.size();i++){
    //     cout<<ans[i]<<' ';
    // }
    for(int i=1;i<str.size();i++){
        if(ans[i]!=0){
            if(str[i]=='('||str[i]==')'){
                str[i]='(';
                str[ans[i]]=')';
            }
            else{
                str[i]='[';
                str[ans[i]]=']';
            }
        }
    }
    int r=str.size()-1;
    for(int i=1;i<str.size();i++){
        if(flag[i]==0){
            flag[i]=1;
            if((str[i]=='('||str[i]==')')&&(str[r]=='('||str[r]==')')){
                if(str[i]==')'&&str[r]=='('){
                    cout<<"No"<<'\n';
                    return ;
                }
                flag[r]=1;
                r--;
            }
            else if((str[i]=='['||str[i]==']')&&(str[r]=='['||str[r]==']')){
                if(str[i]==']'&&str[r]=='['){
                    cout<<"No"<<'\n';
                    return ;
                }
                flag[r]=1;
                r--;
            }
            else{
                if((str[i]=='('||str[i]==')')&&(str[ans[i]]=='('||str[ans[i]]==')')){
                    if(str[i]==')'&&str[ans[i]]=='('){
                        cout<<"No"<<'\n';
                        return ;
                    }
                    flag[ans[i]]=1;
                }
                else if((str[i]=='['||str[i]==']')&&(str[ans[i]]=='['||str[ans[i]]==']')){
                    if(str[i]==']'&&str[ans[i]]=='['){
                        cout<<"No"<<'\n';
                    return ;
                    }
                    flag[ans[i]]=1;
                }
            }
        }
    }
    cout<<"Yes"<<'\n';
}
signed main() {
	//ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
	//cout << fixed << setprecision(12);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
        for(int i=0;i<=n+5;i++){
            flag[i]=0;
            ans[i]=0;
        }
        e.clear();
        str.clear();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5656kb

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

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: 9ms
memory: 5852kb

input:

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

output:

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

result:

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