QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613958#4212. Bracketslc20110802WA 1ms5608kbC++14726b2024-10-05 15:10:342024-10-05 15:14:29

Judging History

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

  • [2024-10-05 15:14:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5608kb
  • [2024-10-05 15:10:34]
  • 提交

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: 5608kb

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

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

input:

1
1 1

output:

:(

result:

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