QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#565111#9319. Bull FarmEwiGKeiTWA 421ms16912kbC++174.5kb2024-09-15 20:18:182024-09-15 20:18:18

Judging History

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

  • [2024-09-15 20:18:18]
  • 评测
  • 测评结果:WA
  • 用时:421ms
  • 内存:16912kb
  • [2024-09-15 20:18:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n,L,q,b[2005][2005],bb[2005],bbb[2005],pos[2005][5],vis[2005],miss[2005],
    faz[2005],cnt,damn[2005];
vector<pair<pair<int,int>,int>> query[2005];
vector<int> G[2005];
pair<int,int> edge[4005];
string str;
int dfn[2005],low[2005],ind,inSt[2005],bcnt,belong[2005],deg[2005],ans[1000005];
stack<int> st;
bitset<2005> bs[2005];
int getRoot(int x)
{
    if (faz[x]==x) return x;
    return faz[x]=getRoot(faz[x]);
}
void add(int u,int v)
{
    G[u].push_back(v);
}
void Tarjan(int u)
{
    dfn[u]=low[u]=++ind;
    inSt[u]=1; st.push(u);
    for (auto v:G[u])
    {
        if (!dfn[v])
        {
            Tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else
        if (inSt[v]) low[u]=min(low[u],dfn[v]);
    }
    if (low[u]==dfn[u])
    {
        int v;
        bcnt++;
        do
        {
            v=st.top(); st.pop();
            belong[v]=bcnt;
            inSt[v]=false;
        } while (u!=v);
    }
    return;
}
queue<int> Q;
void BFS()
{
    for (int i=1;i<=n;i++)
        if (deg[i]==0)
            Q.push(i);
    while (!Q.empty())
    {
        int u=Q.front();Q.pop();
        for (auto v:G[u])
        {
            bs[v]|=bs[u];
            deg[v]--;
            if (deg[v]==0)
                Q.push(v);
        }
    }
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int T;cin>>T;
    while (T--)
    {
        cin >> n >> L >> q;
        for (int i=1;i<=L;i++)
        {
            damn[i]=0;
            cin >> str;
            str=" "+str;
            for (int j=1;j<=n;j++)
                vis[j]=0;
            for (int j=1;j<=n;j++)
            {
                b[i][j]=(str[j*2-1]-'0')*50+(str[j*2]-'0');
                vis[b[i][j]]++;
            }
            miss[i]=0;
            int notvis=0;
            for (int j=1;j<=n;j++)
                if (!vis[j])
                    miss[i]=j,notvis++;
            if (notvis>1) damn[i]=1;
            int cnt=0;
            for (int j=1;j<=n;j++)
                if (vis[b[i][j]]==2)
                    pos[i][++cnt]=j;
        }
        for (int i=1,u,v,lim;i<=q;i++)
        {
            cin >> str;
            str=" "+str;
            u=(str[1]-'0')*50+str[2]-'0';
            v=(str[3]-'0')*50+str[4]-'0';
            lim=(str[5]-'0')*50+str[6]-'0';
            if (lim==0)
                ans[i]=(u==v);
            else
                query[lim].push_back({{u,v},i});
        }
        for (int i=1;i<=n;i++)
        {
            faz[i]=i;
            G[i].clear();
        }
        cnt=0;
        for (int i=1;i<=L;i++)
        {
            if (!damn[i])
            {
                if (miss[i]==0)
                {
                    for (int j=1;j<=n;j++)
                    {
                        int x=getRoot(j),y=getRoot(b[i][j]);
                        if (x!=y) faz[x]=y;
                    }
                } else
                {
                    edge[++cnt].first=pos[i][1];
                    edge[ cnt].second=miss[i];
                    edge[++cnt].first=pos[i][2];
                    edge[ cnt].second=miss[i];
                }
            }
            for (int j=1;j<=cnt;j++)
                add(getRoot(edge[j].first),getRoot(edge[j].second));
            ind=bcnt=0;
            for (int j=1;j<=n;j++)
            {
                dfn[j]=low[j]=0;
                belong[j]=0;
            }
            for (int j=1;j<=n;j++)
                if (!dfn[j])
                    Tarjan(j);
            for (int j=1;j<=n;j++)
                G[j].clear();
            for (int j=1;j<=bcnt;j++)
            {
                deg[j]=0;
                bs[j]=0;
                bs[j][j]=1;
            }
            for (int j=1;j<=cnt;j++)
                if (belong[getRoot(edge[j].first)]!=belong[getRoot(edge[j].second)])
                {
                    add(belong[getRoot(edge[j].first)],belong[getRoot(edge[j].second)]);
                    deg[belong[getRoot(edge[j].second)]]++;
                }
            BFS();
            for (auto [p,id]:query[i])
                if (bs[belong[getRoot(p.second)]][belong[getRoot(p.first)]])
                    ans[id]=1;
                else
                    ans[id]=0;
        }

        for (int i=1;i<=q;i++)
            cout << ans[i];
        cout << '\n';
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5700kb

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1011
0100

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 9732kb

input:

1
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202

output:

010101

result:

ok single line: '010101'

Test #3:

score: -100
Wrong Answer
time: 421ms
memory: 16912kb

input:

200
10 10 5000
01060:04020305080709
0103070:060204050908
09070503080401060:02
050308010204090:0607
03010502040607080:09
03080109020504060:07
06050:09040302080107
07080305010409060:02
030809010:0204060507
0:060908070201050304
060700
090:03
09080:
070405
010703
0:0100
080601
030600
070206
0:0:09
08040...

output:

011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...

result:

wrong answer 2nd lines differ - expected: '111111011101111011011111111111...1111110111111110111011110101111', found: '111111111101111111111111111111...1111111111111110111111111111111'