QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#671626#7900. Gifts from KnowledgeMCdycWA 25ms35148kbC++233.8kb2024-10-24 13:45:582024-10-24 13:45:59

Judging History

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

  • [2024-10-24 13:45:59]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:35148kb
  • [2024-10-24 13:45:58]
  • 提交

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';
}

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 35148kb

input:

3
3 5
01100
10001
00010
2 1
1
1
2 3
001
001

output:

4
0
2

result:

ok 3 number(s): "4 0 2"

Test #2:

score: 0
Accepted
time: 23ms
memory: 34832kb

input:

15613
10 10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
15 8
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
1 5
00000
5 9
000000000
000000000
0000...

output:

1024
32768
2
32
32768
128
32
16
16
2
16384
16384
128
128
32768
8192
128
64
16384
2
4
2
4096
16
4096
1024
32768
32768
16384
8
128
2
16
4096
8192
32768
8192
8192
16
16384
16384
256
128
8
256
8
4096
512
2
4
32
32
2
64
512
1024
32768
32768
2
64
16384
16
8192
16
256
16
64
8192
8192
64
1024
2
32768
2
4
51...

result:

ok 15613 numbers

Test #3:

score: -100
Wrong Answer
time: 25ms
memory: 34828kb

input:

15759
9 6
000000
000000
000000
000000
000000
000000
000000
000000
000000
5 15
010000000000000
000000000000000
000000000000000
000100000000000
000100000000000
14 12
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000...

output:

512
16
16384
512
1024
4096
32768
4
2
512
512
512
512
8
2
256
16
4096
512
64
16
4096
512
32
32768
8192
32
2048
128
16
4096
64
32768
256
32
16384
8
512
32
2048
8
16
1024
2048
128
64
32
8
512
8
8192
256
8192
32768
2
8
512
512
256
32
2
2048
8192
8
64
8
2
16384
32768
32768
1024
4096
16384
16384
128
256
4...

result:

wrong answer 2380th numbers differ - expected: '0', found: '4'