203292026-01-06 14:20:27hunzombiBináris Sakkcpp17Wrong answer 0/1001.509s11480 KiB
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1e9 + 7;

int r, c, n;
vector<vector<int>> nodes;

bool sort1(vector<int> a, vector<int> b) {
    return (a[0] <= b[0]);
}

bool sort2(vector<int> a, vector<int> b) {
    return (a[1] <= b[1]);
}

bool sort3(vector<int> a, vector<int> b) {
    return (a[1] - a[0] <= b[1] - b[0]);
}

bool sort4(vector<int> a, vector<int> b) {
    return (a[0] + a[1] <= b[0] + b[1]);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> r >> c >> n;

    vector<bool> group(n, false);

    for (int i=0; i < n; i++) {
        int u, v;
        cin >> u >> v;
        nodes.push_back({u, v, i});
    }

    int ans = 0;

    sort(nodes.begin(), nodes.end(), sort1);
    for (int i=1; i < n; i++) {
        vector<int> prev = nodes[i - 1];
        vector<int> cur = nodes[i];
        if (prev[0] == cur[0]) {
            if (!group[prev[2]] && !group[cur[2]]) {
                ans++;
            }
            group[prev[2]] = true;
            group[cur[2]] = true;
        }
    }
    sort(nodes.begin(), nodes.end(), sort2);
    for (int i=1; i < n; i++) {
        vector<int> prev = nodes[i - 1];
        vector<int> cur = nodes[i];
        if (prev[1] == cur[1]) {
            if (!group[prev[2]] && !group[cur[2]]) {
                ans++;
            }
            group[prev[2]] = true;
            group[cur[2]] = true;
        }
    }
    sort(nodes.begin(), nodes.end(), sort3);
    for (int i=1; i < n; i++) {
        vector<int> prev = nodes[i - 1];
        vector<int> cur = nodes[i];
        if (prev[1] - prev[0] == cur[1] - cur[0]) {
            if (!group[prev[2]] && !group[cur[2]]) {
                ans++;
            }
            group[prev[2]] = true;
            group[cur[2]] = true;
        }
    }
    sort(nodes.begin(), nodes.end(), sort4);
    for (int i=1; i < n; i++) {
        vector<int> prev = nodes[i - 1];
        vector<int> cur = nodes[i];
        if (prev[1] + prev[0] == cur[1] - cur[0]) {
            if (!group[prev[2]] && !group[cur[2]]) {
                ans++;
            }
            group[prev[2]] = true;
            group[cur[2]] = true;
        }
    }

    for (int i=0; i < n; i++) {
        if (!group[i]) {
            ans++;
        }
        group[i] = true;
    }

    int res = 1;

    while (ans--) {
        res = (res * 2) % MOD;
    }

    cout << res << '\n';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
subtask20/11
3Accepted1ms316 KiB
4Accepted1ms316 KiB
5Accepted1ms316 KiB
6Accepted1ms316 KiB
7Accepted1ms316 KiB
8Wrong answer3ms316 KiB
9Wrong answer3ms316 KiB
10Runtime error1ms316 KiB
11Wrong answer4ms500 KiB
12Wrong answer4ms316 KiB
13Wrong answer4ms480 KiB
14Runtime error1ms316 KiB
15Runtime error2ms316 KiB
16Runtime error3ms516 KiB
17Runtime error4ms680 KiB
18Accepted1ms504 KiB
subtask30/19
19Runtime error35ms5560 KiB
20Runtime error9ms1648 KiB
21Runtime error8ms1648 KiB
22Runtime error79ms11156 KiB
23Runtime error14ms2796 KiB
24Runtime error18ms1272 KiB
25Runtime error79ms11476 KiB
26Runtime error85ms11392 KiB
27Runtime error93ms11476 KiB
28Runtime error101ms11476 KiB
29Runtime error82ms11404 KiB
30Runtime error107ms11480 KiB
31Runtime error72ms11476 KiB
32Runtime error81ms11396 KiB
subtask40/19
33Accepted4ms316 KiB
34Accepted4ms316 KiB
35Accepted2ms316 KiB
36Accepted2ms512 KiB
37Accepted2ms500 KiB
38Accepted2ms316 KiB
39Accepted4ms564 KiB
40Accepted4ms316 KiB
41Accepted4ms316 KiB
42Accepted4ms432 KiB
43Runtime error1ms316 KiB
44Runtime error2ms316 KiB
45Runtime error3ms316 KiB
46Runtime error3ms316 KiB
47Accepted4ms316 KiB
subtask50/51
48Wrong answer81ms1136 KiB
49Wrong answer228ms2980 KiB
50Wrong answer908ms10460 KiB
51Wrong answer1.148s10912 KiB
52Wrong answer388ms3828 KiB
53Wrong answer555ms5348 KiB
54Accepted222ms2796 KiB
55Accepted71ms1136 KiB
56Wrong answer217ms2796 KiB
57Wrong answer1.389s10964 KiB
58Wrong answer1.401s11220 KiB
59Wrong answer1.485s11220 KiB
60Wrong answer1.509s11220 KiB
61Wrong answer1.388s11220 KiB
62Wrong answer1.401s11220 KiB
63Runtime error82ms11476 KiB
64Runtime error381ms11476 KiB
65Runtime error691ms11424 KiB
66Runtime error908ms11476 KiB
67Accepted1.383s11220 KiB
68Accepted1.404s11220 KiB