QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425755#7894. Many Many HeadsRepeater#WA 1ms3584kbC++201.2kb2024-05-30 16:39:252024-05-30 16:39:27

Judging History

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

  • [2024-05-30 16:39:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2024-05-30 16:39:25]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void repeater()
{
	std::string s; std::cin >> s;

	int n = s.size();

	std::map<std::string, int> cnt;

	std::vector<int> stk;
	std::string cur = "";

	for(auto i : s)
	{
		if(i == '(' || i == ')')
		{
			if(stk.empty()) 
			{
				stk.emplace_back(1);
				cur += "(";
			}
			else
			{
				if(stk.back() == 1) 
				{
					stk.pop_back();
					cur += ")";
					if(stk.empty()) cnt[cur]++, cur = "";
				}
				else
				{
					stk.emplace_back(1);
					cur +="(";
				}
			}
		}
		else
		{
			if(stk.empty()) 
			{
				stk.emplace_back(0);
				cur += "[";
			}
			else
			{
				if(stk.back() == 0) 
				{
					stk.pop_back();
					cur += "]";
					if(stk.empty()) cnt[cur]++, cur = "";
				}
				else
				{
					stk.emplace_back(0);
					cur +="[";
				}
			}
		}
		// std::cerr << cur << "\n";
	}

	// for(auto [x, y] : cnt) std::cerr << x << "\n";

	for(auto [x, y] : cnt) if(y >= 2)
	{
		std::cout << "No\n";
		return;
	}
	std::cout << "Yes\n";
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t; std::cin >> t;
	while(t--) repeater();

	return 0;
}

详细

Test #1:

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

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: 1ms
memory: 3584kb

input:

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

output:

Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]