QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614000#4212. Bracketslc20110802WA 1ms5616kbC++14723b2024-10-05 15:18:172024-10-05 15:20:32

Judging History

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

  • [2024-10-05 15:20:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5616kb
  • [2024-10-05 15:18:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 2e6 + 10;
int n, a[N], ans[N];

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	if(n % 2){cout << "(" << endl; return 0;}

	for(int i = 1; i <= 2 * n; i++)
		cin >> a[i];
	if(a[1] == a[2 * n]){cout << "(" << endl; return 0;}

	ans[a[1]] = 1, ans[a[2 * n]] = -1;
	int cnt = 1;
	for(int i = 1; i <= 2 * n; i++){
		if(ans[a[i]] != 0) continue;
		cnt++; if(cnt <= n / 2) ans[a[i]] = 1;
	}

	int top = 0;
	for(int i = 1; i <= 2 * n; i++){
		top += ans[a[i]];
		if(top < 0){cout << "(" << endl; return 0;}
	}

	for(int i = 1; i <= 2 * n; i++)
		cout << (ans[a[i]] == 1 ? '(' : ')');
	cout << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

1
1 1

output:

(

result:

ok single line: '('

Test #3:

score: 0
Accepted
time: 1ms
memory: 5616kb

input:

4
4 3 1 2 3 2 1 4

output:

(

result:

ok single line: '('

Test #4:

score: 0
Accepted
time: 1ms
memory: 5612kb

input:

4
3 1 2 1 4 3 2 4

output:

(()()())

result:

ok single line: '(()()())'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5604kb

input:

4
2 4 3 1 3 4 2 1

output:

(()))(()

result:

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