QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508879#7900. Gifts from Knowledgeucup-team3591WA 16ms3620kbC++204.0kb2024-08-07 21:06:422024-08-07 21:06:48

Judging History

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

  • [2024-08-07 21:06:48]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3620kb
  • [2024-08-07 21:06:42]
  • 提交

answer

//  __      __          ___                                         ___    __ __
// /\ \  __/\ \        /\_ \                                      /'___'\ /\ \ \
// \ \ \/\ \ \ \     __\//\ \     ___    ___     ___ ___      __ /\_\ /\ \ \ \ \       __   __  __     __   _ __
//  \ \ \ \ \ \ \  /'__'\ \ \   /'___\ / __'\ /' __' __'\  /'__'\/_/// /__\ \ \ \_   /'__'\/\ \/\ \  /'__'\/\''__\
//   \ \ \_/ \_\ \/\  __/ \_\ \_/\ \__//\ \L\ \/\ \/\ \/\ \/\  __/  // /_\ \ \__ ,__\/\  __/\ \ \_/ |/\  __/\ \ \/
//    \ '\___x___/\ \____\/\____\ \____\ \____/\ \_\ \_\ \_\ \____\/\______/ \/_/\_\_/\ \____\ \___/ \ \____\ \_\
//     '\/__//__/  \/____/\/____/\/____/\/___/  \/_/\/_/\/_/\/____/\/_____/     \/_/   \/____/ \/__/   \/____/ \/_/
//   bilibili:24Records
//   link:https://space.bilibili.com/3546387113314828
//   blog link:https://welcome24ever.github.io/24Records/
//
//   Then,we just singing like.
//   Welcome To Forever.
#include "bits/stdc++.h"
using namespace std;
const int Welcome24ever = 0;
#define endl '\n'
#define fixset(x) fixed << setprecision(x)
//#define int long long
typedef long long ll; typedef pair<int,int> PII;
long double pi = acos(-1);
const int MOD = 1e9 + 7; const int N = 2e5+10;
void NeverSayNever() {
    int n, m;
    cin >> n >> m;
    vector<string> mp(n + 1);
    for (int i = 1; i <= n; i++) {
        string str;
        cin >> str;
        mp[i] = ' ' + str;
    }
    vector<vector<int>> one(m + 2);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mp[i][j] == '1') {
                one[j].push_back(i);
            }
        }
    }
    if (m % 2 == 1) {
        if (one[m / 2 + 1].size() > 1) {
            cout << 0 << endl;
            return;
        }
    }
    vector<vector<int>> adj(n * 2 + 2);
    for (int i = 1; i <= n; ++i) {
        adj[i].push_back(i + n);
        adj[i + n].push_back(i);
    }
    bool flag = false;
    for (int i = 1; i <= m / 2; ++i) {
        int cnt = one[i].size() + one[m - i + 1].size();
        if (cnt > 2) {
            flag = true;
            break;
        }
        if (cnt < 2) {
            continue;
        }
        if (one[i].size() == 1) {
            int cur = one[i][0];
            int nxt = one[m - i + 1][0];
            if (cur == nxt) continue;
            adj[cur].push_back(nxt + n);
            adj[nxt + n].push_back(cur);
            adj[nxt].push_back(cur + n);
            adj[cur + n].push_back(nxt);
        } else {
            int cur, nxt;
            if (one[i].size() != 0) {
                cur = one[i][0];
                nxt = one[i][1];
            } else {
                cur = one[m - i + 1][0];
                nxt = one[m - i + 1][1];
            }
            adj[cur].push_back(nxt);
            adj[nxt].push_back(cur);
            adj[cur + n].push_back(nxt + n);
            adj[nxt + n].push_back(cur + n);
        }
    }
    if (flag) {
        cout << 0 << endl;
        return;
    }
    int ans = 1;
    vector<int> color(2 * n + 2, 0);
    auto dfs = [&](auto &&self, int cur, int fa) -> bool {
        for (auto &nxt: adj[cur]) {
            if (color[cur] == color[nxt]) {
                return false;
            }
            if (color[nxt]) {
                continue;
            }
            if (color[cur] == 1) {
                color[nxt] = 2;
            } else {
                color[nxt] = 1;
            }
            if (self(self, nxt, cur) == false) {
                return false;
            }
        }
        return true;
    };
    for (int i = 1; i <= 2 * n; i++) {
        if (color[i] != 0) {
            continue;
        }
        color[i] = 1;
        bool f =dfs(dfs, i, i);
        if (f) {
            ans = ans * 2 % MOD;
        }
    }
    cout << ans << endl;
}
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) {
        NeverSayNever();
    }
    return Welcome24ever;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 16ms
memory: 3620kb

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: 13ms
memory: 3572kb

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: '2'