QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#584483#4212. BracketsciuimWA 1ms8160kbC++142.1kb2024-09-23 14:45:282024-09-23 14:45:29

Judging History

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

  • [2024-09-23 14:45:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8160kb
  • [2024-09-23 14:45:28]
  • 提交

answer

bool M1;
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<" MB\n"
#define look_time cerr<<(clock()-Time)*1.0/CLOCKS_PER_SEC<<'\n'
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#include <assert.h>
#define i128 __int128
#define ll long long
#define uint unsigned
#define ull unsigned long long
#define fo(a,b,c) for(ll a=b;a<=c;++a)
#define re(a,b,c) for(ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define pdd pair<db,db>
#define fi first
#define pb push_back
#define se second
#define ite set<pii> ::iterator
using namespace std;
const ll mod=998244353;
inline ll gi()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9')
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
	{
		x = (x<<1) + (x<<3) + (ch^48);
		ch = getchar();
	}
	return x * f;
}
ll _=1;
const ll inf=2e17+5,iinf=2e9;
const ll N=500005;
ll n,a[N];
set<ll> s,ss;
ll buk[N],cx[N][2],use[N];
void sol()
{
	n=gi();
	fo(i,1,n) buk[i]=1;
	fo(i,1,n*2) a[i]=gi();
	fo(i,1,n*2)
	{
		if(cx[a[i]][0]) cx[a[i]][1]=i;
		else cx[a[i]][0]=i;
	}
	ll nw=0;
	re(i,2*n,1)
	{
		nw+=buk[a[i]];
		if(i==cx[a[i]][1])
		{
			s.insert(-cx[a[i]][0]);
		}
		else
		{
			if(s.find(-i)!=s.end())
			{
				s.erase(-i);
				ss.insert(-cx[a[i]][1]);
			}
		}
		if(nw>0)
		{
			if(ss.size())
			{
				ll x=*ss.begin();
				ss.erase(x);
				use[a[-x]]=1;
				nw-=4;
			}
			else
			{
				nw-=2;
				if(s.size())
				{
					ll x=*s.begin();
					s.erase(x);
					use[a[-x]]=1;
					buk[a[-x]]=-1;
				}
			}
		}
	}
	if(nw!=0)
	{
		cout<<"(";
		return;
	}
	fo(i,1,n*2)
	{
		if(use[a[i]])
		{
			cout<<")";
		}
		else
		{
			cout<<"(";
		}
	}
}
bool M2;
int main()
{
	int Time=clock();
	look_memory;
//	_=gi();
	while(_--)
	{
		sol();
		printf("\n");
	}
	look_time;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

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

input:

1
1 1

output:

(

result:

ok single line: '('

Test #3:

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

input:

4
4 3 1 2 3 2 1 4

output:

(

result:

ok single line: '('

Test #4:

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

input:

4
3 1 2 1 4 3 2 4

output:

(()()())

result:

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

Test #5:

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

input:

4
2 4 3 1 3 4 2 1

output:

()()()()

result:

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

Test #6:

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

input:

4
4 4 3 3 1 2 1 2

output:

(((())))

result:

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

Test #7:

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

input:

4
1 3 1 2 4 4 2 3

output:

()(())()

result:

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

Test #8:

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

input:

11
3 9 10 5 4 7 7 8 11 9 5 3 6 1 2 11 10 6 1 2 4 8

output:

(

result:

ok single line: '('

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 8040kb

input:

20
16 3 16 6 5 6 19 11 15 10 14 18 20 18 8 7 13 1 7 3 8 2 9 17 9 19 12 14 4 2 15 4 11 1 13 5 20 17 10 12

output:

(((()(((()(()((())((())))()())()()))))))

result:

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