QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#650352#7894. Many Many HeadsabsabsWA 5ms3876kbC++233.1kb2024-10-18 14:47:062024-10-18 14:47:11

Judging History

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

  • [2024-10-18 14:47:11]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3876kb
  • [2024-10-18 14:47:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ms(x, y) memset(x, y, sizeof x);
#define debug(x) cout << #x << " = " << x << endl;
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fre                           \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const double esp = 1e-6;
const ull MOD1 = 1610612741;
const ull MOD2 = 805306457;
const ull BASE1 = 1331;
const ull BASE2 = 131;
#define pre(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
char *p1, *p2, buf[100000]; // 快读和同步流二者只能选一个
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
int read()
{
	int x = 0, f = 1;
	char ch = nc();
	while (ch < 48 || ch > 57)
	{
		if (ch == '-')
			f = -1;
		ch = nc();
	}
	while (ch >= 48 && ch <= 57)
		x = x * 10 + ch - 48, ch = nc();
	return x * f;
}
void write(int x)
{
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}
void solve()
{
	string s;
	cin>>s;
	vector<int>a(s.size());
	int tot1=0,tot2=0;
	if(s.size()&1){
		cout<<"No"<<endl;
		return;
	}
	int tot=-1;
	for(int i=0;i<s.size();i++){
		if(s[i] == '(' || s[i] == ')') a[i] = 0;
		else a[i] = 1;
		// if(s[i]=='('||s[i]==')')tot1++;
		// else {
		// 	tot2++;

		// }
	}
	// if(tot1||tot2){
	// 	cout<<"No"<<endl;
	// 	return;
	// }
	// if(s[0])
	vector<int> ve;
	pre(i,1,s.size() - 1)
	{
		if(a[i] != a[i - 1])
		{
			// cout << "No" << endl;
			// return ;
		}
		else ve.push_back(i - 1);
	}
	if(s.size() == 2)
	{
		if(a[0] == a[1])
			cout << "Yes" << endl;
		else cout << "No" << endl;
		return ;
	}
	// for(auto L : ve) cout << L << " ";
	// cout << endl;
	int tp = -1;
	for(int i=0;i<ve.size();i++)
	{
		int l = ve[i] - 1,r = ve[i] + 2;
		int ls = a[ve[i]];
		while(l != tp && r != s.size())
		{
			// cout << ls << " " << a[l] << " " << l << " " << r << endl;
			// cout << s[l] << " " << s[r] << endl;
			if(a[l] == a[r] && ls != a[l])
			{
				ls = a[l];
				l -- ,r ++;
			}
			else 
			{
				cout << "No" << endl;
				return ;
			}
		}
		tp = r;
		if(r + 1 < s.size() && a[r] == a[r + 1])
		{
			cout << "No" << endl;
			return ;
		}
		
	}
	if(s.size() >= 2 && a[0] == a[1] && a[1] == a[s.size() - 1] && a[1] == a[s.size() - 2])
		cout << "No" << endl;
	else 
	cout << "Yes" << endl;
}
// #define LOCAL
signed main()
{
	ios
	// fre
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	auto start = std::chrono::high_resolution_clock::now();
#endif
	
	int t = 1;
	cin >> t;
	while (t--)
		solve();
	
#ifdef LOCAL
	auto end = std::chrono::high_resolution_clock::now();
	cout << "Execution time: "
	<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
	<< " ms" << '\n';
#endif
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3876kb

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: 5ms
memory: 3876kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
No
Yes
Yes
No
No
No
Yes
Yes
Yes
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
No
Yes
Yes
No
No
Yes
Yes
No
No
No
No
Yes
Yes
No
No
Yes
Yes
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No...

result:

wrong answer expected YES, found NO [3rd token]