QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716821#7894. Many Many HeadsshuanglinWA 6ms5904kbC++143.3kb2024-11-06 16:06:552024-11-06 16:06:55

Judging History

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

  • [2024-11-06 16:06:55]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:5904kb
  • [2024-11-06 16:06:55]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 6ms
memory: 5904kb

input:

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

output:

Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No
No
Yes
No
Yes
No
Yes
Yes
Yes
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
Yes
No
No
Yes
No
Yes
No
No
No
Yes
No
Yes
Yes
Yes
No
No
No
No
Yes
No
No
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
Yes
No
No
Yes
Yes
No
Y...

result:

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