QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#361424#8509. Expanding STACKS!ucup-team206#AC ✓0ms0kbC++171.0kb2024-03-23 10:08:132024-03-23 10:08:13

Judging History

This is a historical verdict posted at 2024-03-23 10:08:13.

  • [2024-03-23 10:45:39]
  • 管理员手动重测本题所有提交记录
  • Verdict: AC
  • Time: 3ms
  • Memory: 4008kb
  • [2024-03-23 10:08:13]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2024-03-23 10:08:13]
  • Submitted

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 main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n*2;i++)
    {
        int x;
        cin>>x;
        if(x>0)
            l[x]=i;
        else
            r[-x]=i;
    }
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            int u=i,v=j;
            if(l[u]>l[v])
                swap(u,v);
            if(l[v]<=r[u]&&r[v]>=r[u])
                g[u].push_back(v),g[v].push_back(u);
        }
    memset(c,-1,sizeof(c));
    for(int i=1;i<=n;i++)
        if(c[i]==-1)
        {
            c[i]=0;
            dfs(i);
        }
    for(int i=1;i<=n;i++)
        cout<<"GS"[c[i]];
    cout<<"\n";
}

详细

Test #1:

score: 0
Checker Judgement Failed

input:

2
+2 +1 -1 -2

output:

GG

result: