QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#650605#7894. Many Many HeadsabsabsWA 1ms3764kbC++233.1kb2024-10-18 15:49:022024-10-18 15:49:02

Judging History

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

  • [2024-10-18 15:49:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3764kb
  • [2024-10-18 15:49:02]
  • 提交

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;
}
string s;
int change(char c)
{
	if(c == '(' || c == ')') return 0;
	return 1;
}
void solve()
{
	cin >> s;
	// cout<<s<<endl;
	string str;
	stack<char> st;
	// return;
	for(auto L : s)
	{
		char a='(',b=')',c='[',d=']';
		// cout<<L<<endl;
		if(st.empty()) {
			st.push(L);
			if(change(L))str+=c;
			else str+=a;
			continue;
		}
		if(change(st.top()) == change(L))
		{
			int tp = change(st.top());
			if(tp == 0)
				str += ')';
			else str += ']';
			st.pop();
		}
		else {
			st.push(L);
			if(change(L))str+=c;
			else str+=a;
			continue;
		}
	}
	// cout<<str<<endl;
	// return;
	if(!st.empty())
	{
		cout << "No" << endl;
		return ;
	}
	
	int f = 0;	
	for(int i=0;i<str.size();i++)
	{
		if(i + 1 < str.size() && str[i] == ')' && str[i + 1] == '(')
			f = 1;
		else if(i + 1 < str.size() && str[i] == ']' && str[i + 1] == '[')
			f = 1;
	}
	vector<int>res;
	for(int i=0;i<s.size();i++){
		if(change(str[i])==change(str[i+1]))res.push_back(i);
	}
	int tp=-1;
	for(auto a:res){
		// cout<<a<<endl;
		int l=a,r=a+1;
		while(l>2&&r<s.size()-2){
			if(change(str[l-2])!=change(str[l-1])&&change(str[r+1])!=change(str[r+2])&&change(str[l-1])==change(str[r+1]))f=1;
			// cout<<str[l-2]<<" "<<str[l-1]<<" "<<str[r+1]<<" "<<str[r+2]<<endl;
			l--;
			r++;
			if(l==tp||r==s.size())break;
			tp=l;
		}
	}
	if(f) 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;
}


詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3764kb

input:

2
(([([[([
]]))])]])]

output:

No
No

result:

wrong answer expected YES, found NO [1st token]