QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#299048#7894. Many Many Headsucup-team1303#WA 2ms11692kbC++202.5kb2024-01-06 16:54:472024-01-06 16:54:48

Judging History

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

  • [2024-01-06 16:54:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11692kb
  • [2024-01-06 16:54:47]
  • 提交

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];
// 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]);
	// }
	F(i, 0, SZ(t1) - 1) {
		// debug << n2[t1[i].second] << " " << t1[i + 1].second << endl;
		if (n2[t1[i].second] > t1[i + 1].second && p2[t1[i + 1].first] < t1[i].first) {
			puts("No");
			return;
		}
	}
	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: 0
Wrong Answer
time: 2ms
memory: 11692kb

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:

Yes
No
Yes
Yes
Yes
No

result:

wrong answer expected NO, found YES [4th token]