QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671623#7904. Rainbow SubarrayMCdycWA 0ms35304kbC++233.8kb2024-10-24 13:45:202024-10-24 13:45:20

Judging History

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

  • [2024-10-24 13:45:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:35304kb
  • [2024-10-24 13:45:20]
  • 提交

answer

#include <bits/stdc++.h>

#define int ll
using ll = long long;

const int mod = 1e9 + 7;

using namespace std;

struct SCC
{
    vector<vector<int>> e;
    vector<int> siz;
    vector<int> scc;
    vector<int> dfn;
    vector<int> low;
    vector<bool> ins;
    stack<int> sck;
    int sccn;
    int id;
    int n;

    void dfs(int x)
    {
        ins[x] = 1;
        dfn[x] = ++id;
        low[x] = dfn[x];
        sck.push(x);

        for (auto it : e[x])
        {
            if (!dfn[it])
            {
                dfs(it);
                low[x] = min(low[x], low[it]);
            }
            else if (ins[it])
            {
                low[x] = min(low[x], dfn[it]);
            }
        }

        if (low[x] == dfn[x])
        {
            scc[x] = ++sccn;
            ins[x] = 0;
            siz[sccn] = 1;
            while (sck.top() != x)
            {
                scc[sck.top()] = sccn;
                ins[sck.top()] = 0;
                siz[sccn]++;
                sck.pop();
            }
            sck.pop();
        }
    }

    SCC(int len)
    {
        e.resize(len + 5);
        siz.resize(len + 5);
        scc.resize(len + 5);
        dfn.resize(len + 5);
        low.resize(len + 5);
        ins.resize(len + 5);
        n = len;
        id = 0;
        sccn = 0;
        while (!sck.empty())
            sck.pop();
    }

    void addedge(int from, int to)
    {
        e[from].push_back(to);
    }

    void GetScc()
    {
        for (int i = 1; i <= n; i++)
        {
            if (!dfn[i])
                dfs(i);
        }
    }
};

int r, c;
string str[1000010];
int cor[100010];

void solve();

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int __ = 1;
    cin >> __;

    while (__--)
        solve();

    return 0;
}

void solve()
{
    cin >> r >> c;
    for (int i = 1; i <= r; i++)
    {
        cin >> str[i];
        str[i] = " " + str[i];
    }

    SCC graph(r);

    for (int i = 1; i <= c; i++)
    {
        int cnt = 0;
        for (int j = 1; j <= r; j++)
        {
            if (str[j][i] == '1')
                cnt++;
            if (str[j][c - i + 1] == '1')
                cnt++;
        }

        if (cnt > 2)
        {
            cout << "0\n";
            return;
        }
    }

    for (int i = 1; i <= c; i++)
    {
        int u = 0, v = 0;
        for (int j = 1; j <= r; j++)
        {
            if (str[j][i] == '1' || str[j][c - i + 1] == '1')
            {
                if (u == 0)
                    u = j;
                else
                    v = j;
            }
        }

        if (v != 0 && u != v)
        {
            graph.addedge(u, v);
            graph.addedge(v, u);
        }
    }

    graph.GetScc();

    for (int i = 1; i <= r; i++)
        cor[i] = 0;
    queue<int> q;

    // q.push(1);
    // cor[1] = 1;

    set<int> st;
    for (int i = 1; i <= r; i++)
    {
        if (st.find(graph.scc[i]) == st.end())
        {
            st.insert(graph.scc[i]);
            q.push(i);
            cor[i] = 1;
        }
    }

    while (!q.empty())
    {
        int x = q.front();
        q.pop();

        for (auto it : graph.e[x])
        {
            if (cor[it] == 0)
            {
                cor[it] = -cor[x];
                q.push(it);
            }
            else
            {
                if (cor[it] != -cor[x])
                {
                    cout << "0\n";
                    return;
                }
            }
        }
    }

    int ans = 1;
    for (int i = 1; i <= graph.sccn; i++)
    {
        // if (graph.siz[i] < 2)
        //     continue;

        ans = ans * 2 % mod;
    }

    cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 35304kb

input:

5
7 5
7 2 5 5 4 11 7
6 0
100 3 4 5 99 100
5 6
1 1 1 1 1
5 50
100 200 300 400 500
1 100
3

output:

128
64
0
32
2

result:

wrong answer 1st lines differ - expected: '4', found: '128'