QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#705234#7900. Gifts from Knowledgeyeah14RE 21ms83920kbC++174.7kb2024-11-02 22:37:542024-11-02 22:37:55

Judging History

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

  • [2024-11-02 22:37:55]
  • 评测
  • 测评结果:RE
  • 用时:21ms
  • 内存:83920kb
  • [2024-11-02 22:37:54]
  • 提交

answer

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define i128 _int128
#define fi first
#define se second 
#define pb push_back
#define endl '\n'
#define int long long

const ll INF = 0x3f3f3f3f;
const ll N = 1e6 + 9;
const int mod = 1e9+7;

// inline int read(){
//     int ans=0,sign=1;
//     char ch = getchar();
//     while(ch<'0'||ch>'9'){
//         if(ch=='-'){
//             sign=-1;
//         }
//         ch=getchar();
//     }
//     while(ch>='0'&&ch<='9'){
//         ans = ans*10 + ch-'0';
//         ch = getchar();
//     }
//     return ans*sign;
// }

int fp(int a, int x, int mod) {
    int ans = 1;
    while (x) {
        if (x & 1)ans *= a%mod;
        a *= a%mod;
        a %= mod;
        x /=2;
    }
    return ans %= mod;
}


int fa[N];
vector<int>cc[N];//第i行为1的
vector<int>rr[N];//第i列为1的
map<int, int>mp;
map<int, int>mpp;
bool p[N];
string s[N];
set<int>ans;

int find(int p) {
    if (fa[p] != p)return fa[p] = find(fa[p]);
    else return fa[p];
}

void solve() {

    int r, c;
    cin >> r >> c;
    bool flag = 0;
    //初始化
    for (int i = 1; i <= r; i++) {
        fa[i] = i;
        rr[i].clear();
        p[i] = 0;
    }
    for (int i = 1; i <= c; i++) {
        cc[i].clear();
    }
    mp.clear();
    mpp.clear();
    ans.clear();
    //
    int cnt = 0;//无影响
    for (int i = 1; i <= r; i++) {
        cin >> s[i];
        s[i] = '0' + s[i];
        for (int j = 1; j <= c; j++) {
            if (s[i][j] == '1') {
                mp[j]++;
                cc[i].push_back(j);
                rr[j].push_back(i);
                if (mp[j] >= 3) {
                    flag = 1;
                }
                
            }
        }
        int len = cc[i].size();
        int l = 0, r = len-1;
        bool ff = 0;
        if (len % 2 == 1 && c % 2 == 1) {
            if (cc[i][(len - 1) / 2] != c / 2)ff = 1;
        }
        else if(len % 2 == 1)ff = 1;
        if (!ff) {
            while (l < r) {
                if (cc[i][l] + cc[i][r] != c)ff = 1;
                l++, r--;
            }
        }
        if (!ff) {
            p[i] = 1;
            cnt++;
            for (int j = 0; j < len; j++) {
                mpp[cc[i][j]]++;
                if (mpp[cc[i][j]] >= 2)flag = 1;
            }
        }
        
    }
    if (flag) {
        cout << 0 << endl;
        return;
    }
    else if (r == 1) {
        cout << 2 << endl;
        return;
    }
    else if (c == 1) {
        if (mp[1] >= 2)cout << 0 << endl;
        else cout << fp(2, r, mod) << endl;
        return;
    }
    else {
        for (int i = 1; i <= c; i++) {
            if (mp[i] >= 2 && mpp.count(i) != 0) {
                for (int j = 0; j < rr[i].size(); j++) {
                    if (p[rr[i][j]])continue;
                    p[rr[i][j]] = 1;
                    int t = rr[i][j];
                    for (int k = 0; k < cc[t].size(); k++) {
                        mp[cc[t][k]]--;
                        mp[c - cc[t][k]]++;
                        mpp[cc[t][k]]++;
                        if (mpp[cc[t][k]] >= 2) {
                            cout << 0 << endl;
                            return;
                        }
                    }
                }
            }
        }
        for (int i = 1; i <= c; i++) {
            if (mp[i] >= 3) {
                cout << 0 << endl;
                return;
            }
        }
        for (int i = 1; i <= r; i++) {
            if (p[i])continue;
            for (int j = 0; j < cc[i].size(); j++) {
                int t = cc[i][j];
                for (int k = 0; k < rr[t].size(); k++) {
                    int tt = rr[t][k];
                    if (p[tt])continue;
                    fa[find(tt)] = find(i);
                }
                t = c-cc[i][j];
                for (int k = 0; k < rr[t].size(); k++) {
                    int tt = rr[t][k];
                    if (p[tt])continue;
                    fa[find(tt)] = find(i);
                }
            }
        }
        int cntt = 0;//无限制块;
        for (int i = 1; i <= r; i++) {
            if (p[i])continue;
            ans.insert(find(i));
        }
        cntt = ans.size();
        cout << fp(2, cnt, mod) * fp(2, cntt, mod) % mod << endl;
    }
}





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

    int _ = 1;
    // fac[0]=1;
    // for(int i=1;i<=N-9;++i)fac[i]=(fac[i-1]*i)%mod;
    cin >> _;

    while (_--)solve();

    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 83664kb

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: 21ms
memory: 83920kb

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

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:


result: