QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425779 | #7894. Many Many Heads | Repeater# | WA | 6ms | 3792kb | C++20 | 2.0kb | 2024-05-30 16:53:00 | 2024-05-30 16:53:01 |
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())
{
std::string tmp = "";
std::array<int, 2> tcnt{0, 0};
for(int i = 1; i < cur.size() - i; i++)
{
tmp += cur[i];
tmp += cur[cur.size() - i - 1];
if(cur[i] == '(') tcnt[0]++;
else tcnt[1]++;
tmp = "";
}
if(tcnt[0] >= 2 || tcnt[1] >= 2)
{
std::cout << "No\n";
return;
}
tmp += cur[0];
tmp += cur.back();
cnt[tmp]++, 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())
{
std::string tmp = "";
std::array<int, 2> tcnt{0, 0};
for(int i = 1; i < cur.size() - i; i++)
{
tmp += cur[i];
tmp += cur[cur.size() - i - 1];
if(cur[i] == '(') tcnt[0]++;
else tcnt[1]++;
tmp = "";
}
if(tcnt[0] >= 2 || tcnt[1] >= 2)
{
std::cout << "No\n";
return;
}
tmp += cur[0];
tmp += cur.back();
cnt[tmp]++, cur = "";
}
}
else
{
stk.emplace_back(0);
cur +="[";
}
}
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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
Wrong Answer
time: 6ms
memory: 3792kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes No No Yes No No Yes No No Yes No No Yes No No No No No No No No No No No Yes No No No No No No No Yes No No No No Yes No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [20th token]