QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672735#7900. Gifts from Knowledgexh_team#WA 13ms3532kbC++202.7kb2024-10-24 18:35:072024-10-24 18:35:07

Judging History

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

  • [2024-10-24 18:35:07]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3532kb
  • [2024-10-24 18:35:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1E9 + 7;

void no() {
    cout << 0 << '\n';
}
void solve() {
    int n, m;
    cin >> n >> m;

    vector<string> s(n);
    vector<int> fix(m);
    vector<vector<int>> p(m), h(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        for (int j = 0; j < m; j++) {
            s[i][j] -= '0';
        }
        for (int l = 0, r = m - 1; l <= r; l++, r--) {
            if (l == r) {
                if (s[i][l]) fix[l]++;
            } else {
                if (s[i][l] && s[i][r]) {
                    fix[l]++, fix[r]++;
                } else if (s[i][l]) {
                    p[l].emplace_back(i);
                } else if (s[i][r]) {
                    p[r].emplace_back(i);
                }
            }
        }
    }

    for (int l = 0, r = m - 1; l <= r; l++, r--) {
        if (l == r) {
            if (fix[l] > 1) return no();
        } else {
            if (fix[l] > 1) return no();
            if (fix[l] == 1 && p[l].size() + p[r].size() > 0) return no();
            if (p[l].size() + p[r].size() > 2) return no();
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (!fix[j] && s[i][j]) {
                h[i].emplace_back(j);
                // cout << i << ' ' << j << endl;
            }
        }
    }

    vector<int> col(n, -1);

    function<bool(int, int)> dfs = [&](int x, int o) {
        // cout << x << endl;
        col[x] = o;
        for (int i : h[x]) {
            if (o == 0) {
                for (int y : p[i]) {
                    if (col[y] == -1) {
                        if (!dfs(y, o ^ 1)) {
                            return false;
                        }
                    } else if (x != y && col[y] == col[x]) {
                        return false;
                    }
                }
            } else {
                for (int y : p[m - i - 1]) {
                    if (col[y] == -1) {
                        if (!dfs(y, o ^ 1)) {
                            return false;
                        }
                    } else if (x != y && col[y] == col[x]) {
                        return false;
                    }
                }
            }
        }
        return true;
    };

    int res = 1;
    for (int i = 0; i < n; i++) {
        if (col[i] == -1 && !h[i].empty()) {
            if (dfs(i, 0)) {
                res = res * 2 % MOD;
            } else {
                res = 0;
            }
        }       
    }
    cout << res << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);

    int tt;
    cin >> tt;
    while (tt--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

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