QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314333#7894. Many Many HeadsCall_me_EricWA 0ms3888kbC++171.5kb2024-01-25 15:40:552024-01-25 15:40:56

Judging History

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

  • [2024-01-25 15:40:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3888kb
  • [2024-01-25 15:40:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
bool stmemory;
namespace Call_me_Eric{
inline int read(){
    int x = 0, f = 1;char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}
    return x * f;
}
const int maxn = 2e5 + 10;
char ch[maxn];int n;
bool getbrack(char ch){if(ch == '[' || ch == ']')return 0;return 1;}
char brack(bool opt, bool lft){if(opt == 0){return lft == 0 ? '[' : ']';}return lft == 0 ? '(' : ')';}
void solve(){
    scanf("%s",ch + 1);n = strlen(ch + 1);int cnt = 0;
    stack<int> stk;while(stk.size())stk.pop();
    for(int i = 1;i <= n;i++){
        if(stk.empty()){stk.push(i);continue;}
        int x = stk.top();
        if(getbrack(ch[x]) == getbrack(ch[i])){
            ch[x] = brack(getbrack(ch[x]),0);
            ch[i] = brack(getbrack(ch[i]),1);stk.pop();
        }
        else{stk.push(i);}
        cnt += stk.empty();
    }
    if(!stk.empty() || cnt >= 2){puts("No");return;}
    for(int i = 1;i < n;i++)if(ch[i] == ch[i + 1]){puts("No");return;}
    puts("Yes");return;
}
void main(){
    int T = read();
    while(T--){solve();}
    return;
}
};
bool edmemory;
signed main(){
    auto stclock = clock();
    Call_me_Eric::main();
    auto edclock = clock();
    cerr << (&stmemory - &edmemory) / 1024.0 / 1024.0 << " Mib cost.\n";
    cerr << (edclock - stclock) * 1.0 / CLOCKS_PER_SEC << " Sec cost.\n";
    return 0;
}

詳細信息

Test #1:

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

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

input:

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

output:

No
No

result:

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