QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637653#7900. Gifts from Knowledgeyumingsk#ML 18ms35048kbC++203.4kb2024-10-13 13:40:232024-10-13 13:40:24

Judging History

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

  • [2024-10-13 13:40:24]
  • 评测
  • 测评结果:ML
  • 用时:18ms
  • 内存:35048kb
  • [2024-10-13 13:40:23]
  • 提交

answer

#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";

using namespace std;
const int Mod = 998244353;
using ll = long long;
string s[1000005];
vector<pair<int, int>> e[1000005];
const int mod = 1e9 + 7;
int vis[1000005];
int dfs(int u, int fa)
{
    // cout << u << ' ' << fa << '\n';
    for (auto [v, ch] : e[u])
    {
        if (v == fa)
            continue;
        if (vis[v] != -1 && vis[v] != vis[u] ^ ch)
        {
            // cout << "SS " << u << ' ' << v << ' ' << vis[u] << " " << vis[v] << '\n';
            return 0;
        }
        vis[v] = vis[u] ^ ch;
        if (dfs(v, u) == 0)
            return 0;
    }
    return 1;
}
void solve()
{
    int r, c;
    cin >> r >> c;
    for (int i = 1; i <= r; i++)
    {
        e[i].clear();
        vis[i] = -1;
        cin >> s[i];
        s[i] = " " + s[i];
    }
    ll ans = 1;
    for (int j = 1; j <= (c + 1) / 2; j++)
    {
        vector<int> tmp1;
        vector<int> tmp0;
        int fh = 0;
        for (int i = 1; i <= r; i++)
        {
            if (s[i][j] == '1')
            {
                tmp1.push_back(i);
                if (tmp1.size() > 2)
                {
                    fh = 1;
                    break;
                }
            }
        }
        for (int i = 1; i <= r; i++)
        {
            if (s[i][c - j + 1] == '1')
            {
                tmp0.push_back(i);
                if (tmp0.size() > 2)
                {
                    fh = 1;
                    break;
                }
            }
        }
        if (fh == 1)
        {
            ans = 0;
            break;
        }
        for (auto x1 : tmp1)
        {
            for (auto x2 : tmp0)
            {
                if (x1 == x2)
                    continue;
                e[x1].push_back({x2, 0});
                e[x2].push_back({x1, 0});
            }
        }
        for (auto x1 : tmp1)
        {
            for (auto x2 : tmp1)
            {
                if (x1 == x2)
                    continue;
                e[x1].push_back({x2, 1});
                e[x2].push_back({x1, 1});
            }
        }
        for (auto x1 : tmp0)
        {
            for (auto x2 : tmp0)
            {
                if (x1 == x2)
                    continue;
                e[x1].push_back({x2, 1});
                e[x2].push_back({x1, 1});
            }
        }
    }
    for (int i = 1; i <= r; i++)
    {
        if (vis[i] != -1)
            continue;
        vis[i] = 0;
        if (dfs(i, 0))
        {
            ans = ans * 2 % mod;
        }
        else
        {
            // cout << i << "\n";
            ans = 0;
        }
    }
    // for (int i = 1; i <= r; i++)
    // {
    //     cout << vis[i] << '\n';
    // }
    cout << ans << '\n';
}
int main()
{
    IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
    clock_t start_time = clock();
#endif
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
#ifndef ONLINE_JUDGE
    cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 35048kb

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: 18ms
memory: 35048kb

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
Memory Limit Exceeded

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:


result: