QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533906#7900. Gifts from KnowledgePhangRE 39ms34956kbC++142.1kb2024-08-26 16:36:012024-08-26 16:36:01

Judging History

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

  • [2024-08-26 16:36:01]
  • 评测
  • 测评结果:RE
  • 用时:39ms
  • 内存:34956kb
  • [2024-08-26 16:36:01]
  • 提交

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;
            }
        }
        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: 34956kb

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: 39ms
memory: 33560kb

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:

512

result: