QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#340412#4212. BracketsCrysflyWA 1ms7904kbC++172.9kb2024-02-28 23:40:002024-02-28 23:40:01

Judging History

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

  • [2024-02-28 23:40:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7904kb
  • [2024-02-28 23:40:00]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 600005
#define inf 0x3f3f3f3f

int n,a[maxn],to[maxn],buc[maxn];
char res[maxn];

signed main()
{
	n=read()*2;
	For(i,1,n){
		a[i]=read();
		if(buc[a[i]]){
			int x=buc[a[i]];
			to[x]=i,to[i]=x;
		}
		buc[a[i]]=i;
	}
	set<int>s;
	For(i,1,n) if(i&1) s.insert(i);
	int now=0;
	For(i,1,n){
		if(to[i]>i){
			int x=to[i];
		//	cout<<"i,x "<<i<<" "<<x<<"\n";
			auto it=s.lower_bound(x);
			if(it!=s.end()){
				s.erase(it);
				res[i]=res[x]='(';
				it=s.lower_bound(i);
				if(it!=s.end())s.erase(it);
			}
			else res[i]=res[x]=')';
		}
		if(res[i]=='(')++now;
		else --now;
		if(now<0){
			cout<<"(";
			exit(0);
		}
	}
	For(i,1,n)putchar(res[i]);
	return 0;
}
/*

*/

詳細信息

Test #1:

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

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

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

input:

1
1 1

output:

(

result:

ok single line: '('

Test #3:

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

input:

4
4 3 1 2 3 2 1 4

output:

(

result:

ok single line: '('

Test #4:

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

input:

4
3 1 2 1 4 3 2 4

output:

(()()())

result:

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

Test #5:

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

input:

4
2 4 3 1 3 4 2 1

output:

()()()()

result:

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

Test #6:

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

input:

4
4 4 3 3 1 2 1 2

output:

(((())))

result:

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

Test #7:

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

input:

4
1 3 1 2 4 4 2 3

output:

()(())()

result:

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

Test #8:

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

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:

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