数据似乎有一点点水
查看原帖
数据似乎有一点点水
93699
dyf_DYF楼主2021/1/30 15:47

这个代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 30010;
struct node
{
    int son[2];
    int fail;
};
struct tireT
{
    node g[maxn];
    int contaminate[maxn];
    int hed;
    int build()
    {
        hed++;
        g[hed].son[0] = 0, g[hed].son[1] = 0;
        g[hed].fail = 0;
        return hed;
    }
    void initACM()
    {
        queue<int> q;
        if (g[0].son[0])
            q.push(g[0].son[0]);
        if (g[0].son[1])
            q.push(g[0].son[1]);
        while (!q.empty())
        {
            int x = q.front();


            q.pop();
            for (int i = 0; i < 2; i++)
            {
                int son = g[x].son[i], fl = g[x].fail;
                if (!son)
                {
                    g[x].son[i] = g[fl].son[i];
                    continue;
                }
                g[son].fail = g[fl].son[i];
                contaminate[son] |= contaminate[g[fl].son[i]];
                q.push(son);
            }
        }
    }
    void ins(string str)
    {
        int pos = 0;
        for (int i = 0; i < str.size(); i++)
        {
            if (!g[pos].son[str[i] - '0'])
                g[pos].son[str[i] - '0'] = build();
            pos = g[pos].son[str[i] - '0'];
        }
        contaminate[pos] = 1;
    }
} ACM;
int vis[maxn], indfn[maxn];
bool dfs(int x)
{
    for (int i = 0; i < 2; i++)
    {
        int son=ACM.g[x].son[i];
        if (!ACM.contaminate[son])
        {
            if (vis[son])
            {
                if (indfn[son])
                    return true;
            }
            else
            {
                indfn[son] = 1;
                vis[x] = 1;
                if (dfs(son))
                    return true;
                indfn[son] = 0;
            }
        }
    }
    return false;
}
int main()
{
    int n;
    cin >> n;
    string s;
    while (n--)
    {
        cin >> s;
        ACM.ins(s);
    }
    ACM.initACM();
    if (dfs(1))//!
        cout << "TAK" << endl;
    else
        cout << "NIE" << endl;
    return 0;
}

第96行,此处应该是if(dfs(0)),我打成了dfs(1)

但是把这题水过去了

对于这个错误 一组显而易见的hack数据是:

2

00

11

正确答案是TAK,实际输出却是NIE

建议加一组卡这个小错误的数据

2021/1/30 15:47
加载中...