QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624505#7900. Gifts from KnowledgeZeoy#WA 12ms3588kbC++202.2kb2024-10-09 15:59:322024-10-09 15:59:32

Judging History

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

  • [2024-10-09 15:59:32]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:3588kb
  • [2024-10-09 15:59:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define endl "\n"
const int N = 1e6 + 10;
const ll inf = 1ll << 60, mod = 1e9 + 7;

ll ksm(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}

void solve() {
    int n, m; cin >> n >> m;
    vector<string> a(n + 10);
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] = " " + a[i];
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '1') cnt += 1;
        }
    }
    if (cnt > m) {
        cout << 0 << endl;
        return;
    }
    vector<int> val(n + 10);
    vector<int> b(m + 10);
    for (int i = 1; i <= n; ++i) {
        int x = 0, y = 0;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '1') {
                y += 1;
                if (!b[j] && !b[m - j + 1]) x += 1;
                else if (b[j] && b[m - j + 1]) {
                    cout << 0 << endl;
                    return;
                }
            }
        }
        if (x == y) val[i] += 1;
        for (int j = 1; j <= m; ++j) {
            b[j] |= (a[i][j] == '1');
        }
    }
    b = vector<int>(m + 10, 0);
    for (int i = n; i >= 1; --i) {
        int x = 0, y = 0;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == '1') {
                y += 1;
                if (!b[j] && !b[m - j + 1]) x += 1;
                else if (b[j] && b[m - j + 1]) {
                    cout << 0 << endl;
                    return;
                }
            }
        }
        if (x == y) val[i] += 1;
        for (int j = 1; j <= m; ++j) {
            b[j] |= (a[i][j] == '1');
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += (val[i] == 2);
    }
    cout << ksm(2, ans + 1) << endl;
}
/*
3
3 5
01100
10001
00010
2 1
1
1
2 3
001
001

1
3 3
100
010
001

1
4 5
01100
00011
10000
00000

1
2 3
010
010
*/

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
    cin >> _;
    while(_--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 12ms
memory: 3588kb

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:

2048
65536
4
64
65536
256
64
32
32
4
32768
32768
256
256
65536
16384
256
128
32768
4
8
4
8192
32
8192
2048
65536
65536
32768
16
256
4
32
8192
16384
65536
16384
16384
32
32768
32768
512
256
16
512
16
8192
1024
4
8
64
64
4
128
1024
2048
65536
65536
4
128
32768
32
16384
32
512
32
128
16384
16384
128
20...

result:

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