QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#425755 | #7894. Many Many Heads | Repeater# | WA | 1ms | 3584kb | C++20 | 1.2kb | 2024-05-30 16:39:25 | 2024-05-30 16:39:27 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void repeater()
{
std::string s; std::cin >> s;
int n = s.size();
std::map<std::string, int> cnt;
std::vector<int> stk;
std::string cur = "";
for(auto i : s)
{
if(i == '(' || i == ')')
{
if(stk.empty())
{
stk.emplace_back(1);
cur += "(";
}
else
{
if(stk.back() == 1)
{
stk.pop_back();
cur += ")";
if(stk.empty()) cnt[cur]++, cur = "";
}
else
{
stk.emplace_back(1);
cur +="(";
}
}
}
else
{
if(stk.empty())
{
stk.emplace_back(0);
cur += "[";
}
else
{
if(stk.back() == 0)
{
stk.pop_back();
cur += "]";
if(stk.empty()) cnt[cur]++, cur = "";
}
else
{
stk.emplace_back(0);
cur +="[";
}
}
}
// std::cerr << cur << "\n";
}
// for(auto [x, y] : cnt) std::cerr << x << "\n";
for(auto [x, y] : cnt) if(y >= 2)
{
std::cout << "No\n";
return;
}
std::cout << "Yes\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t; std::cin >> t;
while(t--) repeater();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
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: 1ms
memory: 3584kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]