6553 | 2023-12-09 01:25:14 | RRoli | Bináris Sakk | cpp17 | Time limit exceeded 30/100 | 2.099s | 7164 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(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 | 2036 KiB | ||||
2 | Accepted | 3ms | 2200 KiB | ||||
subtask2 | 11/11 | ||||||
3 | Accepted | 3ms | 2424 KiB | ||||
4 | Accepted | 3ms | 2576 KiB | ||||
5 | Accepted | 3ms | 2768 KiB | ||||
6 | Accepted | 3ms | 2976 KiB | ||||
7 | Accepted | 3ms | 3196 KiB | ||||
8 | Accepted | 3ms | 3416 KiB | ||||
9 | Accepted | 3ms | 3480 KiB | ||||
10 | Accepted | 4ms | 3604 KiB | ||||
11 | Accepted | 4ms | 3944 KiB | ||||
12 | Accepted | 4ms | 3900 KiB | ||||
13 | Accepted | 4ms | 3896 KiB | ||||
14 | Accepted | 6ms | 3892 KiB | ||||
15 | Accepted | 6ms | 4024 KiB | ||||
16 | Accepted | 6ms | 4108 KiB | ||||
17 | Accepted | 7ms | 4304 KiB | ||||
18 | Accepted | 3ms | 4176 KiB | ||||
subtask3 | 0/19 | ||||||
19 | Time limit exceeded | 2.065s | 4712 KiB | ||||
20 | Accepted | 801ms | 4848 KiB | ||||
21 | Accepted | 564ms | 4908 KiB | ||||
22 | Time limit exceeded | 2.046s | 6604 KiB | ||||
23 | Accepted | 1.983s | 5456 KiB | ||||
24 | Accepted | 203ms | 5012 KiB | ||||
25 | Time limit exceeded | 2.099s | 6876 KiB | ||||
26 | Time limit exceeded | 2.053s | 6868 KiB | ||||
27 | Time limit exceeded | 2.062s | 6880 KiB | ||||
28 | Time limit exceeded | 2.066s | 6884 KiB | ||||
29 | Time limit exceeded | 2.063s | 7164 KiB | ||||
30 | Time limit exceeded | 2.059s | 6864 KiB | ||||
31 | Time limit exceeded | 2.071s | 6920 KiB | ||||
32 | Time limit exceeded | 2.062s | 6900 KiB | ||||
subtask4 | 19/19 | ||||||
33 | Accepted | 4ms | 4656 KiB | ||||
34 | Accepted | 4ms | 4752 KiB | ||||
35 | Accepted | 3ms | 4704 KiB | ||||
36 | Accepted | 3ms | 4724 KiB | ||||
37 | Accepted | 3ms | 4728 KiB | ||||
38 | Accepted | 3ms | 4820 KiB | ||||
39 | Accepted | 4ms | 4840 KiB | ||||
40 | Accepted | 4ms | 4740 KiB | ||||
41 | Accepted | 4ms | 4740 KiB | ||||
42 | Accepted | 4ms | 4744 KiB | ||||
43 | Accepted | 6ms | 4740 KiB | ||||
44 | Accepted | 6ms | 4896 KiB | ||||
45 | Accepted | 7ms | 4740 KiB | ||||
46 | Accepted | 7ms | 4652 KiB | ||||
47 | Accepted | 4ms | 4728 KiB | ||||
subtask5 | 0/51 | ||||||
48 | Accepted | 421ms | 5052 KiB | ||||
49 | Time limit exceeded | 2.085s | 4412 KiB | ||||
50 | Time limit exceeded | 2.069s | 6116 KiB | ||||
51 | Time limit exceeded | 2.042s | 6320 KiB | ||||
52 | Time limit exceeded | 2.078s | 4916 KiB | ||||
53 | Time limit exceeded | 2.069s | 5248 KiB | ||||
54 | Time limit exceeded | 2.065s | 4632 KiB | ||||
55 | Accepted | 314ms | 4912 KiB | ||||
56 | Time limit exceeded | 2.072s | 4476 KiB | ||||
57 | Time limit exceeded | 2.065s | 6904 KiB | ||||
58 | Time limit exceeded | 2.053s | 6804 KiB | ||||
59 | Time limit exceeded | 2.049s | 6984 KiB | ||||
60 | Time limit exceeded | 2.062s | 6904 KiB | ||||
61 | Time limit exceeded | 2.085s | 6920 KiB | ||||
62 | Time limit exceeded | 2.073s | 7060 KiB | ||||
63 | Time limit exceeded | 2.085s | 6844 KiB | ||||
64 | Time limit exceeded | 2.062s | 6912 KiB | ||||
65 | Time limit exceeded | 2.058s | 6844 KiB | ||||
66 | Time limit exceeded | 2.062s | 7056 KiB | ||||
67 | Time limit exceeded | 2.046s | 7056 KiB | ||||
68 | Time limit exceeded | 2.049s | 6972 KiB |