QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#654794#7900. Gifts from KnowledgeLurkInShadowRE 0ms3516kbC++173.2kb2024-10-18 22:14:092024-10-18 22:14:09

Judging History

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

  • [2024-10-18 22:14:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3516kb
  • [2024-10-18 22:14:09]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define ls u << 1
#define rs u << 1 | 1
#define ff first
#define ss second
#define pb push_back
#define p_q priority_queue
#define INF 0x7FFFFFFF
#define INFF 9223372036854775807
#define den(a) cout << #a << " = " << a << "\n";
#define deg(a) cout << #a << " = " << a << " ";
using namespace std;
using TIII = tuple<int,int,int>;
using PII = pair<int, int>;
using ULL = unsigned long long;
using ld = long double;

const int MOD = 1e9 + 7;
const double eps = 1e-9;
const int N = 5e6 + 10;
int fa[2 * N],n,m;
vector<string> g;
int find(int x)
{
    if(fa[x] == x) return fa[x];
    return fa[x] = find(fa[x]);
}
void unionn(int u,int v)
{
    int x = find(u),y = find(v);
    if(x == y) return;
    fa[y] = x;
}
int qpow(int base,int power)
{
    int res = 1;
    while(power)
    {
        if(power & 1) res = res * base % MOD;
        power >>= 1;
        base = base * base % MOD;
    }
    return res;
}

void solve()
{
    cin >> n >> m;
    g.clear();
    for(int i = 0;i < 2 * n;i ++) fa[i] = i;
    for(int i = 0;i < n;i ++)
    {
        string s;
        cin >> s;
        g.pb(s);
    }
    int sc = 0;
    for(int i = 0;i < m;i ++)
    {
        int c = 0;
        for(int j = 0;j < n;j ++)
        {
            if(g[j][i] == '1') c ++;
        }
        if(c > 2)
        {
            cout << 0 << '\n';
            return;
        }
        sc += c;
        if(sc > m)
        {
            cout << 0 << '\n';
            return;
        }
    }

    for(int i = 0,j = m - 1;i < j;i ++,j --)
    {
        vector<int> L,R;
        for(int k = 0;k < n;k ++)
        {
            if(g[k][i] == '1') L.pb(k);
            if(g[k][j] == '1') R.pb(k);
        }
        if(L.size() + R.size() > 2)
        {
            cout << 0 << '\n';
            return;
        }
        if(L.size() == 2)
        {
            unionn(L[0],L[1] + n);
            unionn(L[1],L[0] + n);
        }
        else if(R.size() == 2)
        {
            unionn(R[0],R[1] + n);
            unionn(R[1],R[0] + n);
        }
        else
        {
            unionn(L[0],R[0]);
            unionn(L[0] + n,R[0] + n);
        }
    }

    int cnt = 0;
    for(int i = 0;i < n;i ++)
    {
        if(find(i) == find(i + n))
        {
            cout << 0 << '\n';
            return;
        }
    }
    for(int i = 0;i < 2 * n;i ++)
    {
        if(fa[i] == i) cnt ++;
    }
    cout << qpow(2,cnt / 2) << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

/*
          /\7    ∠_/
          / │   / /
     │ Z _,< /   /`ヽ
     │     ヽ   /  〉
          Y     `  /  /
     イ● 、 ●  ⊂⊃〈  /
     ()  へ    | \〈
          >ー 、_  ィ  │ //
          / へ   / ノ<| \\
          ヽ_ノ  (_/  │//
          7       |/
          >―r ̄ ̄`ー―_
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3516kb

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: -100
Runtime Error

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:


result: