QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371346#8509. Expanding STACKS!arnold518WA 1ms3848kbC++171.3kb2024-03-30 07:36:112024-03-30 07:36:12

Judging History

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

  • [2024-03-30 07:36:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3848kb
  • [2024-03-30 07:36:11]
  • 提交

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");
}

詳細信息

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