-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathE.cpp
136 lines (127 loc) · 3.17 KB
/
E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// LUOGU_RID: 159490445
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <unordered_map>
#include <stack>
#include <functional>
#include <unordered_set>
#include <numeric>
#include <fstream>
#include <cstring>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#include <iostream>
#include <set>
#include <vector>
int visited[5000];
int g[5000][5000];
bool check(int target, vector<PII> &towers) {
int n = towers.size();
memset(g, 0, sizeof g);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (i == j) {
continue;
}
if (abs(towers[i].first - towers[j].first) + abs(towers[i].second - towers[j].second) > target) {
g[i][j] = true;
g[j][i] = true;
}
}
}
memset(visited, 0, sizeof visited);
function<bool(int, int)> bigraph = [&] (int i, int col) {
visited[i] = col;
for (int next = 0; next < n; ++next) {
if (!g[i][next]) {
continue;
}
if (visited[next] == col || (visited[next] == 0 && !bigraph(next, -col))) {
return false;
}
}
return true;
};
for (int i = 0; i < n; ++i) {
if (!visited[i] && !bigraph(i, 1)) {
return false;
}
}
return true;
}
LL expo(int i) {
LL M = 1e9+7;
if (i == 0) {
return 1;
}
LL res = expo(i / 2);
res = res * res;
if (i % 2 == 1) {
res *= 2;
}
return res % M;
}
void solve(vector<PII> &towers) {
int n = towers.size();
int left = 0, right = 10000;
while (left + 1 < right) {
int mid = left + (right - left) / 2;
if (check(mid, towers)) {
right = mid;
} else {
left = mid;
}
}
int len = right;
if (check(left, towers)) {
len = left;
}
memset(g, 0, sizeof g);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (i == j) {
continue;
}
if (abs(towers[i].first - towers[j].first) + abs(towers[i].second - towers[j].second) > len) {
g[i][j] = true;
g[j][i] = true;
}
}
}
memset(visited, 0, sizeof visited);
function<bool(int, int)> dfs = [&] (int pa, int i) {
visited[i] = true;
int res = 1;
for (int next = 0; next < n; ++next) {
if (!g[i][next] || next == pa || visited[next]) {
continue;
}
res += dfs(i, next);
}
return res;
};
int count = 0;
for (int i = 0; i < n; ++i) {
if (!visited[i]) {
count++;
}
dfs(-1, i);
}
cout << len << endl;
cout << expo(count) << endl;
}
int main() {
int n;
cin >> n;
vector<PII> towers(n);
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
towers[i] = {x, y};
}
solve(towers);
return 0;
}