QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643084 | #7894. Many Many Heads | 666ldc | WA | 14ms | 3620kb | C++17 | 3.1kb | 2024-10-15 18:40:42 | 2024-10-15 18:40:42 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define int long long
#define endl '\n'
using i128 = __int128;
using i64 = long long;
using f128 = long double;
using u64 = unsigned long long;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const i64 inf = 2e18;
//-------------------------------------------
void solve()
{
string s;
cin >> s;
vector<int> stk;
bool flag = false;
map<char, int> hx;
hx['('] = 0, hx[')'] = 0;
hx['['] = 1, hx[']'] = 1;
vector<int> v[2];
for (int i = 0; i < s.size(); i++)
{
int id = hx[s[i]];
v[id].push_back(i);
if (!stk.empty() && id == stk.back())
stk.pop_back();
else
stk.push_back(id);
}
if (!stk.empty())
{
cout << "No" << endl;
return;
}
// 有4个连续的且差值为偶数的相同括号序列
auto check = [&](vector<int> &v)
{
vector<int> cnt, stk;
for (int i = 1; i < v.size(); i++)
cnt.push_back(v[i] - v[i - 1] - 1);
int ct = 0;
for (int i = 0; i < cnt.size(); i++)
{
// cerr << cnt[i] << endl;
if (cnt[i] % 2 == 1)
{
if (ct > 0)
{
int sum = cnt[i];
while (!stk.empty())
{
sum += stk.back();
if (stk.back() % 2 == 1)
{
stk.pop_back();
ct--;
break;
}
else
{
stk.pop_back();
}
}
stk.push_back(sum);
}
else
{
ct++;
stk.push_back(cnt[i]);
}
}
else
{
stk.push_back(cnt[i]);
}
// cerr << stk.size() << endl;
if (stk.size() >= 3)
{
bool flag = false;
for (int j = stk.size() - 1; j + 3 >= stk.size(); j--)
{
//cerr << stk[j] << " " << i << " " << j << " " << stk.size() - 3 << endl;
if (stk[j] % 2 == 1)
{
flag = true;
break;
}
}
if (!flag)
{
return true;
}
}
}
return false;
};
// check(v[0]);
if (check(v[0]) || check(v[1]))
cout << "No" << endl;
else
cout << "Yes" << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
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: 3616kb
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: 14ms
memory: 3620kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes Yes No Yes No No Yes No Yes Yes No No Yes No No No No Yes No No No No No No No No No No No No No No Yes No No No No Yes No No No No No No No 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 ...
result:
wrong answer expected YES, found NO [43rd token]