QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#362236 | #8509. Expanding STACKS! | ucup-team206# | WA | 1ms | 3808kb | C++17 | 1.3kb | 2024-03-23 14:42:18 | 2024-03-23 14:42:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+1e2+7;
int n,c[N];
vector<int> g[N];
int l[N],r[N];
void dfs(int x)
{
for(auto v:g[x])
{
if(c[v]==-1)
c[v]=c[x]^1,dfs(v);
else if(c[v]!=(c[x]^1))
{
cout<<"*\n";
exit(0);
}
}
}
int p[N];
int ans[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n*2;i++)
{
int x;
cin>>x;
p[i]=x;
if(x>0)
l[x]=i;
else
r[-x]=i;
}
vector<int> v1,v2;
r[0]=1e9;
v1.push_back(0),v2.push_back(0);
for(int i=1;i<=n*2;i++)
{
int x=p[i];
if(x<0)
{
if(v1.back()==-x)
v1.pop_back();
else if(v2.back()==-x)
v2.pop_back();
else
{
cout<<"*\n";
return 0;
}
}
else
{
if(r[v1.back()]>r[v2.back()])
v1.swap(v2);
if(r[v1.back()]>r[x])
v1.push_back(x);
else
v2.push_back(x);
}
}
for(int i=1;i<=n;i++)
cout<<"GS"[ans[i]];
cout<<"\n";
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
2 +2 +1 -1 -2
output:
GG
result:
ok correct
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3808kb
input:
2 +1 +2 -1 -2
output:
GG
result:
wrong answer client leaving is not the top of its stack