QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#299066 | #7894. Many Many Heads | ucup-team1303# | WA | 24ms | 13992kb | C++20 | 2.8kb | 2024-01-06 17:01:39 | 2024-01-06 17:01:39 |
Judging History
answer
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T &x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T &x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int N = 1e6 + 10;
int type[N];
int n1[N], n2[N], p1[N], p2[N], q[N];
// bool t[N];
void zhk() {
string st;
cin >> st;
int n = st.size();
// F(i, 1, n) s1[i] = s2[i] = 1e9;
st = ' ' + st;
// bool c1 = true, c2 = true;
int lst1 = 0, lst2 = 0;
vector <pair <int, int>> t1, t2;
F(i, 1, n) {
if (st[i] == ')') st[i] = '(';
if (st[i] == ']') st[i] = '[';
if (st[i] == '(') {
if (lst1) t1.emplace_back(lst1, i), lst1 = 0, type[i] = SZ(t1), st[i] = ')';
else lst1 = i, type[i] = t1.size();
} else {
if (lst2) t2.emplace_back(lst2, i), lst2 = 0, type[i] = SZ(t2), st[i] = ']';
else lst2 = i, type[i] = t2.size();
}
}
set <int> S;
S.insert(1e9);
F(i, 1, n) {
if (st[i] == '(') S.insert(t1[type[i]].second);
if (st[i] == ')') S.erase(i);
n1[i] = *S.begin();
}
// debug << S.size() << endl;
// debug << st << endl;
F(i, 1, n) {
if (st[i] == '[') S.insert(t2[type[i]].second);
if (st[i] == ']') S.erase(i);
n2[i] = *S.begin();
}
S.clear();
S.insert(0);
DF(i, n, 1) {
if (st[i] == ')') S.insert(t1[type[i]].first);
if (st[i] == '(') S.erase(i);
p1[i] = *S.rbegin();
}
DF(i, n, 1) {
if (st[i] == ']') S.insert(t2[type[i]].first);
if (st[i] == '[') S.erase(i);
p2[i] = *S.rbegin();
}
// F(i, 2, n) {
// chkmin(s1[i], s1[i - 1]);
// chkmin(s2[i], s2[i - 1]);
// }
// int mx = 0;
int r = 0;
F(i, 0, SZ(t1)) {
while (r && n2[t1[q[r]].first] < t1[i].first) r--;
if (r && p2[t1[i].first] < t1[q[r]].first) {
puts("No");
return;
}
while (r && n2[t1[q[r]].first] < n2[t1[i].first]) r--;
q[++r] = i;
}
r = 0;
F(i, 0, SZ(t2)) {
while (r && n1[t2[q[r]].first] < t2[i].first) r--;
if (r && p1[t2[i].first] < t2[q[r]].first) {
puts("No");
return;
}
while (r && n1[t2[q[r]].first] < n1[t2[i].first]) r--;
q[++r] = i;
}
// F(i, 0, SZ(t2) - 1)
// if (n1[t2[i].second] > t2[i + 1].second && p1[t2[i + 1].first] < t2[i].first) {
// puts("No");
// return;
// }
puts("Yes");
}
signed main() {
int _ = 1;
cin >> _;
while (_--) zhk();
return 0;
}
/* why?
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13992kb
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: 13808kb
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: 24ms
memory: 13808kb
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 No No No No No No No Yes No Yes No No No No No Yes No No No No Yes No No No No No Yes No Yes No No No No No No No No No No No No No No No No No No Yes No No No No No No No No ...
result:
wrong answer expected YES, found NO [36th token]