QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#571787#4212. BracketszhaohaikunWA 0ms7764kbC++23873b2024-09-18 08:40:372024-09-18 08:40:38

Judging History

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

  • [2024-09-18 08:40:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7764kb
  • [2024-09-18 08:40:37]
  • 提交

answer

// test
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
using namespace std;
const int N = 1e6;
int n, p[N], nxt[N], h[N], ans[N];
set < int > st;
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	L(i, 1, n * 2)
		cin >> p[i], nxt[h[p[i]]] = i, h[p[i]] = i;
	L(i, 1, n)
		st.insert(i * 2 - 1);
	L(i, 1, n * 2) 
		if(nxt[i]) {
			auto p = st.lower_bound(nxt[i]);
			if(p != st.end()) {
				// int w = *p;
				st.erase(p), p = st.lower_bound(i);
				if(p != st.end()) return puts("("), 0;
				st.erase(p), ans[i] = ans[nxt[i]] = 1;
				// else st.insert(w);
			}
		}
	if (st.size()) return puts("("), 0;
	// L(i, 1, n * 2) {
	// 	pre[i] = pre[i - 1] + ans[i] - (!ans[i]);
	// 	if(pre[i] < 0) return cout << "(\n", 0;
	// }
	L(i, 1, n * 2) cout << (ans[i] ? '(' : ')');
	return 0;
} 

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7764kb

input:

2
1 2 1 2

output:

(

result:

wrong answer 1st lines differ - expected: '()()', found: '('