QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533905#7900. Gifts from KnowledgePhangWA 46ms33988kbC++142.1kb2024-08-26 16:34:372024-08-26 16:34:37

Judging History

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

  • [2024-08-26 16:34:37]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:33988kb
  • [2024-08-26 16:34:37]
  • 提交

answer

#include<bits/stdc++.h>
#define rep1(i, a, b) for(int i = a; i <= b; ++i)
#define rep2(i, a, b) for(int i = a; i >= b; --i)
#define ft first
#define sd second
#define pii pair <int, int> 
#define ll long long
#define pb push_back
#define ptc putchar
#define ld long double
#define debug puts("------------------")
const int N = 1e6 + 10, mod = 1e9 + 7;
using namespace std;
int T, n, pos[N][3], pa[N << 1], sz[N << 1], vis[N << 1];
vector <char> s[N];
int find(int x) {return x == pa[x] ? x : pa[x] = find(pa[x]);}
void merge(int u, int v) {
    u = find(u); v = find(v);
    if(u == v) return ;
    pa[u] = v; sz[v] += sz[u];
}
int main() {
    cin >> T;
    while(T--) {
        int n, m, flg = 0; cin >> n >> m;
        // debug; return 0;
        rep1(i, 1, m) pos[i][1] = pos[i][2] = 0;
        rep1(i, 1, n) {
            s[i].resize(m + 1, ' ');
            rep1(j, 1, m) {
                cin >> s[i][j];
                if(s[i][j] == '0') continue;
                int id = min(j, m - j + 1);
                if(!pos[id][1]) pos[id][1] = i;
                else if(!pos[id][2]) pos[id][2] = i;
                else flg = 1;
            }
        }
        rep1(i, 1, m / 2) flg |= !pos[i][2];
        if(m & 1) flg |= pos[m + 1 >> 1][2];
        if(flg) {puts("0"); continue;}
        rep1(i, 1, 2 * n) pa[i] = i, sz[i] = 1, vis[i] = 0;
        rep1(i, 1, m / 2) {
            int id1 = pos[i][1], id2 = pos[i][2]; if(id1 == id2) continue;
            // cout << id1 << ' ' << s[id1].size() << ' ' << i << ' ' << s[id1][i] << '\n';
            // cout << id2 << ' ' << s[id2].size() << ' ' << i << ' ' << s[id2][i] << '\n';
            if(s[id1][i] != s[id2][i]) merge(id1, id2), merge(id1 + n, id2 + n);
            else merge(id1, id2 + n), merge(id1 + n, id2);
        }
        ll ans = 1;
        rep1(i, 1, n) {
            int id1 = find(i), id2 = find(i + n);
            if(id1 == id2) flg = 1;
            if(vis[id1] || vis[id2]) continue;
            vis[id1] = vis[id2] = 1;
            ans <<= 1; ans %= mod;
        }
        cout << (flg ? 0 : ans) << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 33216kb

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
Wrong Answer
time: 46ms
memory: 33988kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8192
0
0
0
0
0
0
0
0
0
0
0
0
0
0
32
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
16384
0
0
0
2048
0
1024
32768
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
16
0
0
0
0
0
0
0
0
0
0
0
2048
0
0
0
2
0
0
...

result:

wrong answer 1st numbers differ - expected: '1024', found: '0'