QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#371346 | #8509. Expanding STACKS! | arnold518 | WA | 1ms | 3848kb | C++17 | 1.3kb | 2024-03-30 07:36:11 | 2024-03-30 07:36:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2000;
int N, A[MAXN+10], B[MAXN+10];
struct UF
{
int par[MAXN+10], val[MAXN+10];
void init()
{
for(int i=1; i<=N; i++) par[i]=i, val[i]=0;
}
pii Find(int x)
{
if(par[x]==x) return pii(x, 0);
pii t=Find(par[x]);
par[x]=t.first;
val[x]^=t.second;
return pii(par[x], val[x]);
}
bool Union(int x, int y, int t)
{
pii x2=Find(x), y2=Find(y);
t^=x2.second^y2.second;
if(x2.first==y2.first) return t==0;
par[x2.first]=y2.first;
val[x2.first]=t;
return true;
}
}uf;
int main()
{
scanf("%d", &N);
for(int i=1; i<=N+N; i++) scanf("%d", &A[i]);
uf.init();
for(int i=1; i<=N+N; i++)
{
if(A[i]>0)
{
B[A[i]]=i;
}
else
{
int t=-A[i];
for(int j=i-1; j>B[t]; j--)
{
if(A[j]>0 && !uf.Union(A[j], t, 1)) return !printf("*\n");
}
}
}
for(int i=1; i<=N; i++)
{
if(uf.Find(i).second) printf("G");
else printf("S");
}
printf("\n");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3848kb
input:
2 +2 +1 -1 -2
output:
GS
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
2 +1 +2 -1 -2
output:
SG
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
3 +1 +2 +3 -1 -2 -3
output:
*
result:
ok correct
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3796kb
input:
10 +3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10
output:
*
result:
wrong answer team and jury output doesn't agree on whether there's an assignment