QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#361834#8509. Expanding STACKS!ucup-team2303#WA 14ms51500kbC++142.4kb2024-03-23 13:23:282024-03-23 13:23:28

Judging History

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

  • [2024-03-23 13:23:28]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:51500kb
  • [2024-03-23 13:23:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an[2001],cn,fac[1000001],inv[1000001],st[1000001],u[1000001],dp[1000001][3],inf=1e16,mx[2001][2001];
char s[1000001];
struct p{long long q,w;}l[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
vector<int> qu[1000001];
int main()
{
//	freopen("1.in","r",stdin);
	srand((unsigned)(time(0)^(*new int)));
	fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
	inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	scanf("%lld",&a);
	for(int i=1;i<=a*2;i++)
	{
		scanf("%s",s+1);
		b=strlen(s+1);q=0;
		for(int j=2;j<=b;j++)
		{
			q=q*10+s[j]-'0';
		}
		if(s[1]=='+')
		{
			l[q].q=i;
		}
		else
		{
			l[q].w=i;
		}
	}
	for(int i=1;i<=a;i++) mx[l[i].q][l[i].q]=l[i].w;
	for(int i=1;i<=a;i++)
	{
		for(int j=i+1;j<=a;j++)
		{
			mx[i][j]=max(mx[i][j-1],mx[j][j]);
		}
	}
	for(int i=1;i<=a*2;i++) fa[i]=i;
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=a;j++)
		{
			if(i==j||l[i].q>l[j].q) continue;
			if(l[i].w>l[j].w) continue;
			if(mx[l[j].q+1][l[i].w-1]>l[j].w)
			{
				printf("*");
				return 0;
			}
			merge(i+a,j);
			merge(i,j+a);
		}
	}
	for(int i=1;i<=a*2;i++)
	{
		if(v[i]) continue;
		if(find(i)!=i) continue;
		if(i>a) an[i-a]=0,v[i]=v[i-a]=1;
		else an[i]=0,v[i]=v[i+a]=1;
		for(int j=1;j<=a*2;j++)
		{
			if(find(j)==i)
			{
				if((j>a)==(i>a))
				{
					if(j>a) an[j-a]=0,v[j]=v[j-a]=1;
					else an[j]=0,v[j]=v[j+a]=1;
				}
				else
				{
					if(j>a) an[j-a]=1,v[j]=v[j-a]=1;
					else an[j]=1,v[j]=v[j+a]=1;
				}
			}
		}
	}
	for(int i=1;i<=a;i++)
	{
		if(an[i]) putchar('G');
		else putchar('S');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 46044kb

input:

2
+2 +1 -1 -2

output:

SS

result:

ok correct

Test #2:

score: 0
Accepted
time: 14ms
memory: 51500kb

input:

2
+1 +2 -1 -2

output:

GS

result:

ok correct

Test #3:

score: 0
Accepted
time: 7ms
memory: 51324kb

input:

3
+1 +2 +3 -1 -2 -3

output:

*

result:

ok correct

Test #4:

score: 0
Accepted
time: 8ms
memory: 48012kb

input:

10
+3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10

output:

SSSSSSSSSS

result:

ok correct

Test #5:

score: -100
Wrong Answer
time: 13ms
memory: 46616kb

input:

10
+8 -8 +2 +10 -2 -10 +7 -7 +1 -1 +6 -6 +5 +3 +4 +9 -9 -4 -3 -5

output:

SSSSSSSSSS

result:

wrong answer client leaving is not the top of its stack