6554 | 2023-12-09 01:29:53 | RRoli | Bináris Sakk | cpp17 | Time limit exceeded 30/100 | 2.099s | 7668 KiB |
#include <bits/stdc++.h>
using namespace std;
int R, C, N;
vector<int> szulo, meret;
vector<pair<int, int>> koord;
int find(int k) {
if(szulo[k] == k) return k;
return szulo[k] = find(szulo[k]);
}
bool unio(int a, int b) {
a = find(a);
b = find(b);
if(a == b) return true;
if(meret[a] >= meret[b]) {
meret[a] += meret[b];
szulo[b] = a;
} else {
meret[b] += meret[a];
szulo[a] = b;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> R >> C >> N;
szulo.resize(N+1);
meret.resize(N+1);
koord.resize(N+1);
for(int i = 1; i <= N; i++) {
szulo[i] = i;
meret[i] = 1;
}
for(int i = 1; i <= N; i++) {
int r, c;
cin >> r >> c;
koord[i] = make_pair(r, c);
}
for(int i = 1; i < N; i++) {
for(int j = i+1; j <= N; j++) {
if(find(i) != find(j)) {
if(koord[i].first == koord[j].first || koord[i].second == koord[j].second ||
abs(koord[i].first-koord[j].first) == abs(koord[i].second-koord[j].second))
unio(i, j);
}
}
}
int p = 0;
for(int i = 1; i <= N; i++) if(find(i) == i) p++;
int ans = 1;
while(p > 0) {
ans = (ans * 2) % 1000000007;
p--;
}
cout << ans << '\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1892 KiB | ||||
2 | Accepted | 3ms | 2116 KiB | ||||
subtask2 | 11/11 | ||||||
3 | Accepted | 3ms | 2168 KiB | ||||
4 | Accepted | 3ms | 2292 KiB | ||||
5 | Accepted | 3ms | 2524 KiB | ||||
6 | Accepted | 3ms | 2760 KiB | ||||
7 | Accepted | 3ms | 2948 KiB | ||||
8 | Accepted | 4ms | 3284 KiB | ||||
9 | Accepted | 4ms | 3408 KiB | ||||
10 | Accepted | 4ms | 3500 KiB | ||||
11 | Accepted | 6ms | 3724 KiB | ||||
12 | Accepted | 6ms | 3936 KiB | ||||
13 | Accepted | 6ms | 4020 KiB | ||||
14 | Accepted | 6ms | 4028 KiB | ||||
15 | Accepted | 6ms | 4288 KiB | ||||
16 | Accepted | 6ms | 4368 KiB | ||||
17 | Accepted | 6ms | 4368 KiB | ||||
18 | Accepted | 3ms | 4576 KiB | ||||
subtask3 | 0/19 | ||||||
19 | Time limit exceeded | 2.099s | 5188 KiB | ||||
20 | Accepted | 1.225s | 5248 KiB | ||||
21 | Accepted | 952ms | 4932 KiB | ||||
22 | Time limit exceeded | 2.051s | 6960 KiB | ||||
23 | Time limit exceeded | 2.058s | 4348 KiB | ||||
24 | Accepted | 303ms | 4904 KiB | ||||
25 | Time limit exceeded | 2.051s | 6904 KiB | ||||
26 | Time limit exceeded | 2.053s | 6940 KiB | ||||
27 | Time limit exceeded | 2.046s | 6812 KiB | ||||
28 | Time limit exceeded | 2.078s | 6812 KiB | ||||
29 | Time limit exceeded | 2.058s | 6900 KiB | ||||
30 | Time limit exceeded | 2.053s | 7128 KiB | ||||
31 | Time limit exceeded | 2.062s | 7020 KiB | ||||
32 | Time limit exceeded | 2.069s | 7072 KiB | ||||
subtask4 | 19/19 | ||||||
33 | Accepted | 4ms | 5088 KiB | ||||
34 | Accepted | 4ms | 5040 KiB | ||||
35 | Accepted | 3ms | 5104 KiB | ||||
36 | Accepted | 3ms | 5128 KiB | ||||
37 | Accepted | 3ms | 5244 KiB | ||||
38 | Accepted | 3ms | 5328 KiB | ||||
39 | Accepted | 4ms | 5324 KiB | ||||
40 | Accepted | 4ms | 5228 KiB | ||||
41 | Accepted | 4ms | 5232 KiB | ||||
42 | Accepted | 4ms | 5272 KiB | ||||
43 | Accepted | 6ms | 5240 KiB | ||||
44 | Accepted | 6ms | 5492 KiB | ||||
45 | Accepted | 6ms | 5340 KiB | ||||
46 | Accepted | 6ms | 5336 KiB | ||||
47 | Accepted | 4ms | 5332 KiB | ||||
subtask5 | 0/51 | ||||||
48 | Accepted | 442ms | 5736 KiB | ||||
49 | Time limit exceeded | 2.062s | 5020 KiB | ||||
50 | Time limit exceeded | 2.062s | 6720 KiB | ||||
51 | Time limit exceeded | 2.058s | 6984 KiB | ||||
52 | Time limit exceeded | 2.059s | 5544 KiB | ||||
53 | Time limit exceeded | 2.062s | 5924 KiB | ||||
54 | Time limit exceeded | 2.075s | 5060 KiB | ||||
55 | Accepted | 328ms | 5644 KiB | ||||
56 | Time limit exceeded | 2.071s | 4876 KiB | ||||
57 | Time limit exceeded | 2.046s | 7512 KiB | ||||
58 | Time limit exceeded | 2.073s | 7600 KiB | ||||
59 | Time limit exceeded | 2.058s | 7560 KiB | ||||
60 | Time limit exceeded | 2.042s | 7516 KiB | ||||
61 | Time limit exceeded | 2.062s | 7496 KiB | ||||
62 | Time limit exceeded | 2.062s | 7540 KiB | ||||
63 | Time limit exceeded | 2.073s | 7472 KiB | ||||
64 | Time limit exceeded | 2.066s | 7512 KiB | ||||
65 | Time limit exceeded | 2.062s | 7536 KiB | ||||
66 | Time limit exceeded | 2.053s | 7604 KiB | ||||
67 | Time limit exceeded | 2.078s | 7668 KiB | ||||
68 | Time limit exceeded | 2.062s | 7656 KiB |