2022 Problems
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +26 -0
- 2022/finals/1142476319774543.jpg +3 -0
- 2022/finals/1175696903384597.jpg +3 -0
- 2022/finals/1310493279783732.jpg +3 -0
- 2022/finals/1327255974690671.jpg +3 -0
- 2022/finals/2468652649959145.jpg +3 -0
- 2022/finals/504150738360453.jpg +3 -0
- 2022/finals/547949757342773.jpg +3 -0
- 2022/finals/556593865835592.jpg +3 -0
- 2022/finals/6502772429739994.jpg +3 -0
- 2022/finals/650302073463012.jpg +3 -0
- 2022/finals/853886435922998.jpg +3 -0
- 2022/finals/876374553707415.jpg +3 -0
- 2022/finals/alphabet_adventuring.cpp +425 -0
- 2022/finals/alphabet_adventuring.in +3 -0
- 2022/finals/alphabet_adventuring.md +72 -0
- 2022/finals/alphabet_adventuring.out +0 -0
- 2022/finals/alphabet_adventuring_sol.md +25 -0
- 2022/finals/cup_counterbalancing.in +42 -0
- 2022/finals/cup_counterbalancing.java +397 -0
- 2022/finals/cup_counterbalancing.md +34 -0
- 2022/finals/cup_counterbalancing.out +7 -0
- 2022/finals/cup_counterbalancing_sol.md +18 -0
- 2022/finals/emerald_exhibiting.cpp +94 -0
- 2022/finals/emerald_exhibiting.in +111 -0
- 2022/finals/emerald_exhibiting.md +47 -0
- 2022/finals/emerald_exhibiting.out +110 -0
- 2022/finals/emerald_exhibiting_sol.md +18 -0
- 2022/finals/hazelnut_harvesting.cpp +356 -0
- 2022/finals/hazelnut_harvesting.in +3 -0
- 2022/finals/hazelnut_harvesting.md +41 -0
- 2022/finals/hazelnut_harvesting.out +160 -0
- 2022/finals/hazelnut_harvesting_sol.md +21 -0
- 2022/finals/ml_modeling.cpp +102 -0
- 2022/finals/ml_modeling.in +3 -0
- 2022/finals/ml_modeling.md +51 -0
- 2022/finals/ml_modeling.out +1000 -0
- 2022/finals/ml_modeling_sol.md +11 -0
- 2022/finals/tile_transposing.cpp +382 -0
- 2022/finals/tile_transposing.in +3 -0
- 2022/finals/tile_transposing.md +61 -0
- 2022/finals/tile_transposing.out +105 -0
- 2022/finals/tile_transposing_sol.md +58 -0
- 2022/quals/1183048075593188.jpg +3 -0
- 2022/quals/1264108514364518.jpg +3 -0
- 2022/quals/356437426702208.jpg +3 -0
- 2022/quals/459254706243127.jpg +3 -0
- 2022/quals/5118404751621442.jpg +3 -0
- 2022/quals/545859687328272.jpg +3 -0
- 2022/quals/569216148234749.jpg +3 -0
.gitattributes
CHANGED
@@ -112,3 +112,29 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
112 |
2023/round2/wiki_race.in filter=lfs diff=lfs merge=lfs -text
|
113 |
2023/round3/double_stars.in filter=lfs diff=lfs merge=lfs -text
|
114 |
2023/round3/similar_ships.in filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
2023/round2/wiki_race.in filter=lfs diff=lfs merge=lfs -text
|
113 |
2023/round3/double_stars.in filter=lfs diff=lfs merge=lfs -text
|
114 |
2023/round3/similar_ships.in filter=lfs diff=lfs merge=lfs -text
|
115 |
+
2022/finals/alphabet_adventuring.in filter=lfs diff=lfs merge=lfs -text
|
116 |
+
2022/finals/hazelnut_harvesting.in filter=lfs diff=lfs merge=lfs -text
|
117 |
+
2022/finals/ml_modeling.in filter=lfs diff=lfs merge=lfs -text
|
118 |
+
2022/finals/tile_transposing.in filter=lfs diff=lfs merge=lfs -text
|
119 |
+
2022/quals/second_flight.in filter=lfs diff=lfs merge=lfs -text
|
120 |
+
2022/quals/second_flight.out filter=lfs diff=lfs merge=lfs -text
|
121 |
+
2022/quals/second_second_friend.in filter=lfs diff=lfs merge=lfs -text
|
122 |
+
2022/quals/second_second_friend.out filter=lfs diff=lfs merge=lfs -text
|
123 |
+
2022/round1/consecutive_cuts_ch1.in filter=lfs diff=lfs merge=lfs -text
|
124 |
+
2022/round1/consecutive_cuts_ch2.in filter=lfs diff=lfs merge=lfs -text
|
125 |
+
2022/round1/lemonade_life.in filter=lfs diff=lfs merge=lfs -text
|
126 |
+
2022/round1/watering_well_ch1.in filter=lfs diff=lfs merge=lfs -text
|
127 |
+
2022/round1/watering_well_ch2.in filter=lfs diff=lfs merge=lfs -text
|
128 |
+
2022/round2/balance_scale.in filter=lfs diff=lfs merge=lfs -text
|
129 |
+
2022/round2/balance_sheet.in filter=lfs diff=lfs merge=lfs -text
|
130 |
+
2022/round2/perfectly_balanced_ch1.in filter=lfs diff=lfs merge=lfs -text
|
131 |
+
2022/round2/perfectly_balanced_ch2.in filter=lfs diff=lfs merge=lfs -text
|
132 |
+
2022/round2/work_life_balance_ch1.in filter=lfs diff=lfs merge=lfs -text
|
133 |
+
2022/round2/work_life_balance_ch2.in filter=lfs diff=lfs merge=lfs -text
|
134 |
+
2022/round3/first_time_ch1.in filter=lfs diff=lfs merge=lfs -text
|
135 |
+
2022/round3/first_time_ch2.in filter=lfs diff=lfs merge=lfs -text
|
136 |
+
2022/round3/fourth_player.in filter=lfs diff=lfs merge=lfs -text
|
137 |
+
2022/round3/second_mistake.in filter=lfs diff=lfs merge=lfs -text
|
138 |
+
2022/round3/third_trie.in filter=lfs diff=lfs merge=lfs -text
|
139 |
+
2022/round3/zero_crossings_ch1.in filter=lfs diff=lfs merge=lfs -text
|
140 |
+
2022/round3/zero_crossings_ch2.in filter=lfs diff=lfs merge=lfs -text
|
2022/finals/1142476319774543.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/1175696903384597.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/1310493279783732.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/1327255974690671.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/2468652649959145.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/504150738360453.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/547949757342773.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/556593865835592.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/6502772429739994.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/650302073463012.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/853886435922998.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/876374553707415.jpg
ADDED
![]() |
Git LFS Details
|
2022/finals/alphabet_adventuring.cpp
ADDED
@@ -0,0 +1,425 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <algorithm>
|
2 |
+
#include <iostream>
|
3 |
+
#include <utility>
|
4 |
+
#include <vector>
|
5 |
+
using namespace std;
|
6 |
+
|
7 |
+
using pii = pair<int, int>;
|
8 |
+
|
9 |
+
struct Req {
|
10 |
+
int ind, t, x, y;
|
11 |
+
vector<int> alph;
|
12 |
+
};
|
13 |
+
|
14 |
+
int pair_cnt;
|
15 |
+
vector<vector<int>> pair_map;
|
16 |
+
|
17 |
+
int N, M, Q;
|
18 |
+
vector<pii> edges;
|
19 |
+
vector<vector<pii>> g;
|
20 |
+
vector<Req> a;
|
21 |
+
vector<int> ans, lnks, lnks_z, lnk_jump, d, par, par_z;
|
22 |
+
vector<vector<int>> top_links, bot_links, bu_links;
|
23 |
+
|
24 |
+
vector<int> dsu;
|
25 |
+
|
26 |
+
int get_dsu_parent(int x) {
|
27 |
+
if (dsu[x] == dsu[dsu[x]]) {
|
28 |
+
return dsu[x];
|
29 |
+
}
|
30 |
+
return dsu[x] = get_dsu_parent(dsu[x]);
|
31 |
+
}
|
32 |
+
|
33 |
+
int get_top_link(int edge_ind, int pair_ind) {
|
34 |
+
if (top_links[edge_ind][pair_ind] == edge_ind) {
|
35 |
+
return edge_ind;
|
36 |
+
}
|
37 |
+
return get_top_link(top_links[edge_ind][pair_ind], pair_ind);
|
38 |
+
}
|
39 |
+
|
40 |
+
int get_edge_ind(int x, int y) {
|
41 |
+
pii edge(x, y);
|
42 |
+
int l = 0, r = M - 1;
|
43 |
+
while (l <= r) {
|
44 |
+
int mid = (l + r) >> 1;
|
45 |
+
if (edges[mid] == edge) {
|
46 |
+
return mid;
|
47 |
+
}
|
48 |
+
if (edges[mid] < edge) {
|
49 |
+
l = mid + 1;
|
50 |
+
} else {
|
51 |
+
r = mid - 1;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
return -1;
|
55 |
+
}
|
56 |
+
|
57 |
+
void precalc() {
|
58 |
+
pair_map.assign(26, vector<int>(26, -1));
|
59 |
+
pair_cnt = 0;
|
60 |
+
for (int z1 = 0; z1 < 26; z1++) {
|
61 |
+
for (int z2 = z1 + 1; z2 < 26; z2++) {
|
62 |
+
pair_map[z1][z2] = pair_cnt++;
|
63 |
+
pair_map[z2][z1] = pair_cnt++;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
void add_edge(int x, int y, int z) {
|
69 |
+
edges.push_back({x, y});
|
70 |
+
g[x].push_back({y, z});
|
71 |
+
}
|
72 |
+
|
73 |
+
int dfs_lnks(int x, int p) {
|
74 |
+
par[x] = p;
|
75 |
+
lnk_jump[x] = x;
|
76 |
+
if (x == p) {
|
77 |
+
d[x] = 0;
|
78 |
+
} else {
|
79 |
+
d[x] = d[p] + 1;
|
80 |
+
}
|
81 |
+
lnks[x] = -1;
|
82 |
+
lnks_z[x] = -1;
|
83 |
+
int best = 0, total = 0;
|
84 |
+
for (auto [y, z] : g[x]) {
|
85 |
+
if (y == p) {
|
86 |
+
par_z[x] = z;
|
87 |
+
continue;
|
88 |
+
}
|
89 |
+
int cur = dfs_lnks(y, x);
|
90 |
+
total += cur;
|
91 |
+
if (cur > best) {
|
92 |
+
best = cur;
|
93 |
+
lnk_jump[x] = lnk_jump[y];
|
94 |
+
lnks[x] = y;
|
95 |
+
lnks_z[x] = z;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
return total + 1;
|
99 |
+
}
|
100 |
+
|
101 |
+
void run_precalc_top(int x, int p) {
|
102 |
+
if (x != p) {
|
103 |
+
int edge_ind = get_edge_ind(x, p);
|
104 |
+
if (p == par[p]) {
|
105 |
+
top_links[edge_ind].assign(pair_cnt, edge_ind);
|
106 |
+
} else {
|
107 |
+
int par_edge_ind = get_edge_ind(p, par[p]);
|
108 |
+
top_links[edge_ind] = top_links[par_edge_ind];
|
109 |
+
}
|
110 |
+
|
111 |
+
if (par[p] != p) {
|
112 |
+
int ppz = par_z[p];
|
113 |
+
for (auto [y, z] : g[p]) {
|
114 |
+
if (y == par[p] || y == x) {
|
115 |
+
continue;
|
116 |
+
}
|
117 |
+
top_links[edge_ind][pair_map[z][ppz]] = edge_ind;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
}
|
121 |
+
for (int i = 0; i < (int)g[x].size(); i++) {
|
122 |
+
int y = g[x][i].first;
|
123 |
+
if (y == p) {
|
124 |
+
continue;
|
125 |
+
}
|
126 |
+
run_precalc_top(y, x);
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
void run_precalc_bot(int x, int p) {
|
131 |
+
for (auto [y, _] : g[x]) {
|
132 |
+
if (y != p) {
|
133 |
+
run_precalc_bot(y, x);
|
134 |
+
}
|
135 |
+
}
|
136 |
+
int ly = lnks[x], lz = lnks_z[x];
|
137 |
+
if (ly != -1) {
|
138 |
+
bot_links[x] = bot_links[ly];
|
139 |
+
for (auto [y, z] : g[x]) {
|
140 |
+
if (y == ly || y == p) {
|
141 |
+
continue;
|
142 |
+
}
|
143 |
+
bot_links[x][pair_map[z][lz]] = x;
|
144 |
+
}
|
145 |
+
} else {
|
146 |
+
bot_links[x].assign(pair_cnt, x);
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
void binary_uplifting() {
|
151 |
+
int sz = (int)g.size();
|
152 |
+
int maxp = 1;
|
153 |
+
while ((1 << maxp) < sz) {
|
154 |
+
++maxp;
|
155 |
+
}
|
156 |
+
++maxp;
|
157 |
+
bu_links.assign(maxp, vector<int>(sz));
|
158 |
+
for (int i = 0; i < sz; i++) {
|
159 |
+
bu_links[0][i] = par[i];
|
160 |
+
}
|
161 |
+
for (int p = 1; p < maxp; p++) {
|
162 |
+
for (int i = 0; i < sz; i++) {
|
163 |
+
bu_links[p][i] = bu_links[p - 1][bu_links[p - 1][i]];
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
void init() {
|
169 |
+
int x = 0, y = 0, z = 0;
|
170 |
+
char c = 0;
|
171 |
+
g.clear();
|
172 |
+
edges.clear();
|
173 |
+
edges.reserve(N << 2);
|
174 |
+
cin >> N;
|
175 |
+
g.resize(N);
|
176 |
+
for (int i = 1; i < N; i++) {
|
177 |
+
cin >> x >> y >> c;
|
178 |
+
--x, --y;
|
179 |
+
z = (int)(c - 'A');
|
180 |
+
add_edge(x, y, z);
|
181 |
+
add_edge(y, x, z);
|
182 |
+
}
|
183 |
+
int t = 0;
|
184 |
+
string s;
|
185 |
+
vector<int> alph;
|
186 |
+
cin >> Q;
|
187 |
+
a.resize(Q);
|
188 |
+
for (int i = 0; i < Q; i++) {
|
189 |
+
Req &r = a[i];
|
190 |
+
cin >> t;
|
191 |
+
--t;
|
192 |
+
r.ind = i;
|
193 |
+
r.t = t;
|
194 |
+
if (t) {
|
195 |
+
cin >> x >> y >> s;
|
196 |
+
--x;
|
197 |
+
alph.resize(s.length());
|
198 |
+
for (int i = 0; i < (int)s.length(); i++) {
|
199 |
+
alph[i] = (int)(s[i] - 'A');
|
200 |
+
}
|
201 |
+
r.x = x;
|
202 |
+
r.y = y;
|
203 |
+
r.alph = alph;
|
204 |
+
} else {
|
205 |
+
y = (int)(g.size());
|
206 |
+
g.push_back({});
|
207 |
+
cin >> x >> c;
|
208 |
+
--x;
|
209 |
+
z = (int)(c - 'A');
|
210 |
+
add_edge(x, y, z);
|
211 |
+
add_edge(y, x, z);
|
212 |
+
r.x = x;
|
213 |
+
r.y = y;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
sort(edges.begin(), edges.end());
|
217 |
+
M = edges.size();
|
218 |
+
top_links.resize(M);
|
219 |
+
|
220 |
+
dsu.resize(g.size());
|
221 |
+
for (int i = 0; i < (int)g.size(); i++) {
|
222 |
+
dsu[i] = i;
|
223 |
+
}
|
224 |
+
|
225 |
+
par.resize(g.size());
|
226 |
+
par_z.resize(g.size());
|
227 |
+
d.resize(g.size());
|
228 |
+
lnks.resize(g.size());
|
229 |
+
lnks_z.resize(g.size());
|
230 |
+
lnk_jump.resize(g.size());
|
231 |
+
|
232 |
+
bot_links.resize(g.size());
|
233 |
+
dfs_lnks(0, 0);
|
234 |
+
binary_uplifting();
|
235 |
+
run_precalc_top(0, 0);
|
236 |
+
run_precalc_bot(0, 0);
|
237 |
+
}
|
238 |
+
|
239 |
+
int get_uplift(int x, int k) {
|
240 |
+
for (int p = (int)bu_links.size() - 1; p >= 0; --p) {
|
241 |
+
if (k & (1 << p)) {
|
242 |
+
x = bu_links[p][x];
|
243 |
+
}
|
244 |
+
}
|
245 |
+
return x;
|
246 |
+
}
|
247 |
+
|
248 |
+
int go_up(int x, int &k, const vector<int> &stop_vector) {
|
249 |
+
int p = par[x];
|
250 |
+
if (x == p) {
|
251 |
+
return x;
|
252 |
+
}
|
253 |
+
int edge_ind = get_edge_ind(x, p), y = 0;
|
254 |
+
for (int _y : stop_vector) {
|
255 |
+
int ny = edges[get_top_link(edge_ind, _y)].second;
|
256 |
+
if (d[y] < d[ny]) {
|
257 |
+
y = ny;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
int dif = d[x] - d[y];
|
261 |
+
if (k < dif) {
|
262 |
+
y = get_uplift(x, k);
|
263 |
+
k = 0;
|
264 |
+
} else {
|
265 |
+
k -= dif;
|
266 |
+
}
|
267 |
+
return y;
|
268 |
+
}
|
269 |
+
|
270 |
+
int go_down(int x, int &k, const vector<int> &stop_vector,
|
271 |
+
const vector<int> &rev_alph) {
|
272 |
+
while (k) {
|
273 |
+
if (lnks[x] == -1) {
|
274 |
+
break;
|
275 |
+
}
|
276 |
+
int y = lnk_jump[x];
|
277 |
+
for (int _y : stop_vector) {
|
278 |
+
int ny = bot_links[x][_y];
|
279 |
+
if (d[y] > d[ny]) {
|
280 |
+
y = ny;
|
281 |
+
}
|
282 |
+
}
|
283 |
+
y = get_dsu_parent(y);
|
284 |
+
int dif = d[y] - d[x];
|
285 |
+
if (k < dif) {
|
286 |
+
y = get_uplift(y, dif - k);
|
287 |
+
k = 0;
|
288 |
+
} else {
|
289 |
+
k -= dif;
|
290 |
+
}
|
291 |
+
if (k) {
|
292 |
+
int ny = -1, nz = 26;
|
293 |
+
for (auto [yy, _zz] : g[y]) {
|
294 |
+
if (yy == par[y] || yy != dsu[yy]) {
|
295 |
+
continue;
|
296 |
+
}
|
297 |
+
int zz = rev_alph[_zz];
|
298 |
+
if (nz > zz) {
|
299 |
+
nz = zz;
|
300 |
+
ny = yy;
|
301 |
+
}
|
302 |
+
}
|
303 |
+
if (ny == -1) {
|
304 |
+
x = y;
|
305 |
+
break;
|
306 |
+
}
|
307 |
+
--k;
|
308 |
+
y = ny;
|
309 |
+
}
|
310 |
+
x = y;
|
311 |
+
}
|
312 |
+
return x;
|
313 |
+
}
|
314 |
+
|
315 |
+
int get_res(int x, int k, const vector<int> &alph) {
|
316 |
+
if (!k) {
|
317 |
+
return x;
|
318 |
+
}
|
319 |
+
vector<int> stop_vector;
|
320 |
+
for (int i = 0; i < (int)alph.size(); i++) {
|
321 |
+
for (int j = i + 1; j < (int)alph.size(); j++) {
|
322 |
+
stop_vector.push_back(pair_map[alph[i]][alph[j]]);
|
323 |
+
}
|
324 |
+
}
|
325 |
+
vector<int> rev_alph(26, -1);
|
326 |
+
for (int i = 0; i < (int)alph.size(); i++) {
|
327 |
+
rev_alph[alph[i]] = i;
|
328 |
+
}
|
329 |
+
if (x != par[x]) {
|
330 |
+
int up_dir = 1;
|
331 |
+
for (auto [y, z] : g[x]) {
|
332 |
+
if (y == par[x] || y != dsu[y]) {
|
333 |
+
continue;
|
334 |
+
}
|
335 |
+
if (rev_alph[par_z[x]] > rev_alph[z]) {
|
336 |
+
up_dir = 0;
|
337 |
+
break;
|
338 |
+
}
|
339 |
+
}
|
340 |
+
if (up_dir) {
|
341 |
+
int pk = k, px = x;
|
342 |
+
x = go_up(x, k, stop_vector);
|
343 |
+
if (k) {
|
344 |
+
int nx = get_uplift(px, pk - k - 1);
|
345 |
+
int y = -1, z = 26;
|
346 |
+
for (auto [ny, _nz] : g[x]) {
|
347 |
+
if (ny == par[x] || ny == nx || ny != dsu[ny]) {
|
348 |
+
continue;
|
349 |
+
}
|
350 |
+
int nz = rev_alph[_nz];
|
351 |
+
if (nz < z) {
|
352 |
+
y = ny;
|
353 |
+
z = nz;
|
354 |
+
}
|
355 |
+
}
|
356 |
+
if (y == -1) {
|
357 |
+
return x;
|
358 |
+
}
|
359 |
+
x = y;
|
360 |
+
--k;
|
361 |
+
}
|
362 |
+
}
|
363 |
+
}
|
364 |
+
if (k) {
|
365 |
+
x = go_down(x, k, stop_vector, rev_alph);
|
366 |
+
}
|
367 |
+
return x;
|
368 |
+
}
|
369 |
+
|
370 |
+
void update_precalc_top(int x) {
|
371 |
+
int p = par[x];
|
372 |
+
if (x == p || p == par[p]) {
|
373 |
+
return;
|
374 |
+
}
|
375 |
+
int par_edge_ind = get_edge_ind(p, par[p]);
|
376 |
+
int ppz = par_z[p], z = -1;
|
377 |
+
for (auto [y, _z] : g[p]) {
|
378 |
+
if (y != x) {
|
379 |
+
continue;
|
380 |
+
}
|
381 |
+
z = _z;
|
382 |
+
break;
|
383 |
+
}
|
384 |
+
for (auto [y, _z] : g[p]) {
|
385 |
+
if (y == par[p] || y != dsu[y]) {
|
386 |
+
continue;
|
387 |
+
}
|
388 |
+
int edge_ind = get_edge_ind(y, p);
|
389 |
+
int pair_ind = pair_map[z][ppz];
|
390 |
+
top_links[edge_ind][pair_ind] = get_top_link(par_edge_ind, pair_ind);
|
391 |
+
}
|
392 |
+
}
|
393 |
+
|
394 |
+
void solve() {
|
395 |
+
ans.assign(Q, -1);
|
396 |
+
for (int i = Q - 1; i >= 0; --i) {
|
397 |
+
const Req &req = a[i];
|
398 |
+
if (req.t) {
|
399 |
+
ans[req.ind] = get_res(req.x, req.y, req.alph);
|
400 |
+
} else {
|
401 |
+
dsu[req.y] = get_dsu_parent(par[req.y]);
|
402 |
+
update_precalc_top(req.y);
|
403 |
+
}
|
404 |
+
}
|
405 |
+
for (int i = 0; i < Q; i++) {
|
406 |
+
if (ans[i] != -1) {
|
407 |
+
cout << " " << ans[i] + 1;
|
408 |
+
}
|
409 |
+
}
|
410 |
+
cout << endl;
|
411 |
+
}
|
412 |
+
|
413 |
+
int main() {
|
414 |
+
ios_base::sync_with_stdio(false);
|
415 |
+
cin.tie(0);
|
416 |
+
precalc();
|
417 |
+
int T;
|
418 |
+
cin >> T;
|
419 |
+
for (int t = 1; t <= T; t++) {
|
420 |
+
init();
|
421 |
+
cout << "Case #" << t << ":";
|
422 |
+
solve();
|
423 |
+
}
|
424 |
+
return 0;
|
425 |
+
}
|
2022/finals/alphabet_adventuring.in
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d92c856f4244d69ddbe7faae1fc95df6d99ff46dc684957d4a0ae5140da3b748
|
3 |
+
size 50941290
|
2022/finals/alphabet_adventuring.md
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Alphonse is assembling an *alphabet tree* and arranging some adventures along the way.
|
2 |
+
|
3 |
+
An alphabet tree is an unrooted tree with \(N\) nodes (numbered from \(1\) to \(N\)) and \(N - 1\) edges. Initially, the \(i\)th edge connects nodes \(A_i\) and \(B_i\) in both directions, and is labeled with a uppercase letter \(C_i\). Two edges incident to a common node are always labeled with different letters.
|
4 |
+
|
5 |
+
Alphonse has \(Q\) events to process, the \(i\)th of which is one of two types:
|
6 |
+
|
7 |
+
* `1` \(U_i\) \(L_i\): Add a new node to the tree by connecting it to node \(U_i\) with a new edge labeled with uppercase letter \(L_i\). Newly added nodes are numbered with integers starting from \(N + 1\) in the order they're added.
|
8 |
+
* `2` \(U_i\) \(K_i\) \(S_i\): Print the final node Alphonse will end up at if he:
|
9 |
+
- Starts a journey at node \(U_i\).
|
10 |
+
- Repeatedly traverses a previously untraversed edge (on this journey). If his current node has multiple untraversed edges, he picks the edge labeled with the letter that comes earliest in the string \(S_i\).
|
11 |
+
- Ends the journey once there are no more untraversed edges at the current node, or \(K_i\) edges have been traversed on the journey.
|
12 |
+
|
13 |
+
Please help Alphonse determine where each journey will take him.
|
14 |
+
|
15 |
+
|
16 |
+
# Constraints
|
17 |
+
|
18 |
+
\(1 \le T \le 20\)
|
19 |
+
\(2 \le N \le 300{,}000\)
|
20 |
+
\(1 \le Q \le 300{,}000\)
|
21 |
+
\(1 \le A_i, B_i \le N\)
|
22 |
+
\(A_i \ne B_i\)
|
23 |
+
\(C_i, L_i, S_{i,j} \in \{\)`'A'`, \(\ldots\), `'Z'`\(\}\)
|
24 |
+
\(1 \le U_i, K_i \le 600{,}000\)
|
25 |
+
|
26 |
+
The sum of \(N\) over all test cases is at most \(1{,}100{,}000\).
|
27 |
+
The sum of \(Q\) over all test cases is at most \(1{,}100{,}000\).
|
28 |
+
|
29 |
+
For each event, it is guaranteed that:
|
30 |
+
- \(U_i\) is a valid node in the tree at the time of the event.
|
31 |
+
- \(L_i\) is different from all existing labels of edges incident to \(U_i\) at the time of the event.
|
32 |
+
- \(S_i\)'s letters are distinct, and are a superset of all edge labels in the tree at the time of the event.
|
33 |
+
|
34 |
+
|
35 |
+
# Input Format
|
36 |
+
|
37 |
+
Input begins with a single integer \(T\), the number of test cases. For each test case, there is first a line containing a single integer \(N\). Then, \(N - 1\) lines follow, the \(i\)th of which contains space-separated integers \(A_i\) and \(B_i\), followed by a space, followed by \(C_i\). Then, there is a line containing the single integer \(Q\). Then, \(Q\) lines follow, the \(i\)th of which is either `1` \(U_i\) \(L_i\) or `2` \(U_i\) \(K_i\) \(S_i\).
|
38 |
+
|
39 |
+
|
40 |
+
# Output Format
|
41 |
+
|
42 |
+
For the \(i\)th test case, print a single line containing `"Case #i: "`, followed by space-separated integers, the answers to all type-2 events.
|
43 |
+
|
44 |
+
|
45 |
+
# Sample Explanation
|
46 |
+
|
47 |
+
{{PHOTO_ID:1175696903384597|WIDTH:550}}
|
48 |
+
|
49 |
+
The first sample case's alphabet tree is depicted above, and yields the following journeys:
|
50 |
+
|
51 |
+
- Event \(1\) traverses \(1 \stackrel{\texttt{M}}{\longrightarrow} 2 \stackrel{\texttt{E}}{\longrightarrow} 6\) (ended after no more edges from node \(6\))
|
52 |
+
- Event \(2\) traverses \(3 \stackrel{\texttt{E}}{\longrightarrow} 1 \stackrel{\texttt{T}}{\longrightarrow} 4 \stackrel{\texttt{A}}{\longrightarrow} 9\) (ended after \(K_2 = 3\) steps)
|
53 |
+
- Event \(3\) traverses \(9 \stackrel{\texttt{A}}{\longrightarrow} 4 \stackrel{\texttt{T}}{\longrightarrow} 1 \stackrel{\texttt{M}}{\longrightarrow} 2\) (ended after \(K_3 = 3\) steps)
|
54 |
+
- Event \(4\) traverses \(8 \stackrel{\texttt{M}}{\longrightarrow} 3 \stackrel{\texttt{E}}{\longrightarrow} 1 \stackrel{\texttt{T}}{\longrightarrow} 4 \stackrel{\texttt{A}}{\longrightarrow} 9\) (ended after no more edges from node \(9\))
|
55 |
+
- Event \(6\) traverses \(8 \stackrel{\texttt{T}}{\longrightarrow} 10\) (ended after no more edges from node \(10\))
|
56 |
+
|
57 |
+
The second and third sample cases are depicted below.
|
58 |
+
|
59 |
+
{{PHOTO_ID:1142476319774543|WIDTH:650}}
|
60 |
+
|
61 |
+
In the second case, the journeys are:
|
62 |
+
|
63 |
+
- Event \(1\) traverses \(1 \stackrel{\texttt{P}}{\longrightarrow} 5 \stackrel{\texttt{C}}{\longrightarrow} 2\) (ended after \(K_1 = 2\) steps)
|
64 |
+
- Event \(2\) traverses \(4 \stackrel{\texttt{P}}{\longrightarrow} 2 \stackrel{\texttt{C}}{\longrightarrow} 5 \stackrel{\texttt{P}}{\longrightarrow} 1\) (ended after \(K_2 = 3\) steps)
|
65 |
+
- Event \(4\) traverses \(4 \stackrel{\texttt{P}}{\longrightarrow} 2 \stackrel{\texttt{C}}{\longrightarrow} 5 \stackrel{\texttt{U}}{\longrightarrow} 6\) (ended after \(K_4 = 3\) steps)
|
66 |
+
- Event \(5\) traverses \(3 \stackrel{\texttt{U}}{\longrightarrow} 2 \stackrel{\texttt{P}}{\longrightarrow} 4\) (ended after no more edges from node \(4\))
|
67 |
+
|
68 |
+
In the third case, the journeys are:
|
69 |
+
|
70 |
+
- Event \(1\) traverses \(3 \stackrel{\texttt{C}}{\longrightarrow} 2 \stackrel{\texttt{A}}{\longrightarrow} 1\) (ended after \(K_1 = 2\) steps)
|
71 |
+
- Event \(2\) traverses \(4 \stackrel{\texttt{E}}{\longrightarrow} 2 \stackrel{\texttt{A}}{\longrightarrow} 1\) (ended after \(K_2 = 2\) steps)
|
72 |
+
- Event \(3\) traverses \(1 \stackrel{\texttt{A}}{\longrightarrow} 2\) (ended after \(K_3 = 1\) steps)
|
2022/finals/alphabet_adventuring.out
ADDED
The diff for this file is too large to render.
See raw diff
|
|
2022/finals/alphabet_adventuring_sol.md
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
The first thing to do is root the tree, for which we can arbitrarily choose node \(1\). Each journey can be done in two phases:
|
2 |
+
1. *Uplifting*: \(k_1\) steps in root's direction (\(k_1\) can be zero).
|
3 |
+
2. *Descent*: \(k_2\) steps in the opposite direction (\(k_2\) can be zero, \(k_1 + k_2 \le K_i\)).
|
4 |
+
|
5 |
+
Indeed, after we descend one step, there is no way to start moving up, because the previous edge will always be the edge we need to go upwards (and we can't traverse an edge twice).
|
6 |
+
|
7 |
+
Next, notice that adding new nodes don't make the problem significantly harder. We can preprocess all type-1 events and construct the full tree, then process events of both types in reverse order: it's easier to remove nodes rather than to add them. For a reverse type-1 event, we'll replace the node with a reference to its parent so that whenever we get to this node, we instantly return to its parent. For some removals, we must repeat until we reached a node that still exists in the tree. A disjoint set union (DSU) data structure can be used to perform these operations efficiently. For each node, we'll use DSU to find the bottommost ancestor that still exists in the tree.
|
8 |
+
|
9 |
+
Now, we'll need a way to perform phase 1 and phase 2 in time faster than \(\mathcal{O}(N + Q)\). For simplicity, we'll describe the solution for an indefinite \(K\). If the destination node is known, we can always backtrack a certain number of steps using binary lifting.
|
10 |
+
|
11 |
+
*Phase 1.* In this problem, we have an radix size of \(R = 26\), so we have only \(26 * 25 = 650\) unique pairs of letters. Let's call a pair of letters \((c_1, c_2)\) *active* if \(c_1\) precedes \(c_2\) in the given string \(S_i\). For each edge and pair of letters, we can precompute the ancestor node where the uplifting ends (due to this pair being active) using depth-first search in \(\mathcal{O}((N + Q) * R^2)\). If we start at some node \(v\) and we need to find the node where uplifting stops, we should do the following:
|
12 |
+
|
13 |
+
1. Start uplifting at node \(v\). Look through all the edges adjacent to \(v\) to make sure the first edge of the traversal will be the edge to its parent. If not, there is no uplifting for the current event.
|
14 |
+
2. Iterate over all active pairs and pick the bottommost precomputed node across all these pairs for the edge from node \(v\) to its parent. This node is the destination of uplifting.
|
15 |
+
|
16 |
+
The total complexity for phase 1 of a single journey is \(\mathcal{O}(R^2)\). We only iterate over at most \(R\) edges and over at most \(R * (R - 1) / 2\) pairs.
|
17 |
+
|
18 |
+
*Phase 2.* This phase is slightly more difficult because we have to pick the right edge by ourselves (where in phase 1, we always took the edge from a node to its parent). One possible strategy is to consider the edge that leads to the largest subtree. For each node and pair of letters, we can precompute the descendant node where the descent ends due to this pair being active. The way we use this data is very similar to phase 1:
|
19 |
+
|
20 |
+
1. Start the descent at node \(v\).
|
21 |
+
2. Iterate over all active pairs and pick the topmost precomputed node \(u\) across all these pairs for the vertex \(v\). It's possible that \(u = v\).
|
22 |
+
3. Look through all edges adjacent to \(u\) for the next step. If there is no such edge, node \(u\) is the destination of our descent. Otherwise, this edge leads to the node we assign to \(v\), and we return to step 2.
|
23 |
+
|
24 |
+
Each time we perform step 3, we reduce the maximum possible number of steps left by at least a half, so at most we will repeat it \(\mathcal{O}(\log(N + Q))\) times for each journey. Since each such step takes \(\mathcal{O}(R^2)\) time, the overall time complexity for phase 2 of a journey is \(\mathcal{O}(\log(N + Q) * R^2)\), and the overall time complexity is therefore \(\mathcal{O}(Q * \log(N + Q) * R^2)\).
|
25 |
+
|
2022/finals/cup_counterbalancing.in
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
7
|
2 |
+
3 1 4
|
3 |
+
0 0
|
4 |
+
2 2
|
5 |
+
4 0
|
6 |
+
5 1 4
|
7 |
+
0 0
|
8 |
+
1 2
|
9 |
+
0 3
|
10 |
+
4 3
|
11 |
+
3 1
|
12 |
+
4 1 1
|
13 |
+
0 0
|
14 |
+
0 1
|
15 |
+
1 1
|
16 |
+
1 0
|
17 |
+
4 3 10
|
18 |
+
0 0
|
19 |
+
1 9
|
20 |
+
10 10
|
21 |
+
10 0
|
22 |
+
4 5 10
|
23 |
+
0 0
|
24 |
+
1 9
|
25 |
+
10 10
|
26 |
+
10 0
|
27 |
+
7 2 10
|
28 |
+
0 0
|
29 |
+
10 2
|
30 |
+
6 3
|
31 |
+
9 6
|
32 |
+
5 9
|
33 |
+
6 5
|
34 |
+
2 8
|
35 |
+
7 5 10
|
36 |
+
0 0
|
37 |
+
10 2
|
38 |
+
6 3
|
39 |
+
9 6
|
40 |
+
5 9
|
41 |
+
6 5
|
42 |
+
2 8
|
2022/finals/cup_counterbalancing.java
ADDED
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import java.io.PrintWriter;
|
2 |
+
import java.text.DecimalFormat;
|
3 |
+
import java.util.ArrayList;
|
4 |
+
import java.util.Arrays;
|
5 |
+
import java.util.Random;
|
6 |
+
import java.util.Scanner;
|
7 |
+
|
8 |
+
public class CupCounterbalancing {
|
9 |
+
static PrintWriter out;
|
10 |
+
|
11 |
+
static void solve(Scanner fs, PrintWriter out, int tt) throws InterruptedException {
|
12 |
+
int n = fs.nextInt(), r = fs.nextInt(), max = fs.nextInt();
|
13 |
+
Vec[] points = new Vec[n];
|
14 |
+
for (int i = 0; i < n; i++) {
|
15 |
+
points[i] = new Vec(fs.nextInt(), fs.nextInt());
|
16 |
+
}
|
17 |
+
double ans = solveNaive1e8(points, r, max);
|
18 |
+
out.println("Case #" + tt + ": " + ans);
|
19 |
+
out.flush();
|
20 |
+
}
|
21 |
+
|
22 |
+
static double solveNaive1e8(Vec[] points, int r, int max) {
|
23 |
+
long time = System.currentTimeMillis();
|
24 |
+
Vec test = new Vec(1, 0).rotate(random.nextDouble()).scale(max / Math.sqrt(1e8));
|
25 |
+
double res = solveNaive(points, r, max, test);
|
26 |
+
return res;
|
27 |
+
}
|
28 |
+
static double solveNaive1e8Multithreaded(
|
29 |
+
Vec[] points, int r, int max, boolean print, int nThreads) throws InterruptedException {
|
30 |
+
long time = System.currentTimeMillis();
|
31 |
+
Thread[] threads = new Thread[nThreads];
|
32 |
+
final double[] answers = new double[nThreads];
|
33 |
+
for (int i = 0; i < threads.length; i++) {
|
34 |
+
final int ii = i;
|
35 |
+
threads[i] = new Thread(null, null, "T") {
|
36 |
+
public void run() {
|
37 |
+
answers[ii] = solveNaive1e8(points, r, max);
|
38 |
+
}
|
39 |
+
};
|
40 |
+
threads[i].start();
|
41 |
+
}
|
42 |
+
for (Thread t : threads) {
|
43 |
+
t.join();
|
44 |
+
}
|
45 |
+
double average = 0;
|
46 |
+
for (double d : answers) {
|
47 |
+
average += d;
|
48 |
+
}
|
49 |
+
return average / nThreads;
|
50 |
+
}
|
51 |
+
|
52 |
+
static Random random = new Random();
|
53 |
+
|
54 |
+
static double solveNaive(Vec[] points, int r, int max, Vec test) {
|
55 |
+
test.x = Math.abs(test.x);
|
56 |
+
test.y = Math.abs(test.y);
|
57 |
+
Vec start = new Vec(0, 0);
|
58 |
+
int row = 0;
|
59 |
+
Vec rotated = test.rot90();
|
60 |
+
Seg[] segs = new Seg[points.length];
|
61 |
+
for (int i = 0; i < points.length; i++) {
|
62 |
+
segs[i] = new Seg(points[i], points[(i + 1) % points.length]);
|
63 |
+
}
|
64 |
+
int worksCount = 0;
|
65 |
+
int allCount = 0;
|
66 |
+
while (true) {
|
67 |
+
Vec rowStart = start.add(rotated.scale(row));
|
68 |
+
if (rowStart.y > max)
|
69 |
+
break;
|
70 |
+
Vec at = rowStart;
|
71 |
+
while (at.x <= max && at.y <= max) {
|
72 |
+
if (at.x >= 0 && at.y >= 0) {
|
73 |
+
if (worksNaive(segs, at, r)) {
|
74 |
+
worksCount++;
|
75 |
+
}
|
76 |
+
allCount++;
|
77 |
+
}
|
78 |
+
at = at.add(test);
|
79 |
+
}
|
80 |
+
row++;
|
81 |
+
}
|
82 |
+
row = -1;
|
83 |
+
while (true) {
|
84 |
+
Vec rowStart = start.add(rotated.scale(row));
|
85 |
+
Vec at = rowStart;
|
86 |
+
boolean hit = false;
|
87 |
+
while (at.x <= max && at.y <= max) {
|
88 |
+
if (at.x >= 0 && at.y >= 0) {
|
89 |
+
hit = true;
|
90 |
+
if (worksNaive(segs, at, r)) {
|
91 |
+
worksCount++;
|
92 |
+
}
|
93 |
+
allCount++;
|
94 |
+
}
|
95 |
+
at = at.add(test);
|
96 |
+
}
|
97 |
+
row--;
|
98 |
+
if (!hit) {
|
99 |
+
break;
|
100 |
+
}
|
101 |
+
}
|
102 |
+
return worksCount / (double) allCount;
|
103 |
+
}
|
104 |
+
|
105 |
+
static boolean worksNaive(Seg[] segs, Vec query, long r) {
|
106 |
+
ArrayList<Vec> intersections = new ArrayList<>();
|
107 |
+
Circle c = new Circle(query, r);
|
108 |
+
for (Seg s : segs) {
|
109 |
+
Vec[] ans = c.intersectSeg(s);
|
110 |
+
if (ans != null) {
|
111 |
+
for (Vec v : ans) {
|
112 |
+
intersections.add(v);
|
113 |
+
}
|
114 |
+
}
|
115 |
+
}
|
116 |
+
double[] angles = new double[intersections.size()];
|
117 |
+
for (int i = 0; i < angles.length; i++) angles[i] = intersections.get(i).sub(query).angle();
|
118 |
+
Arrays.sort(angles);
|
119 |
+
if (angles.length <= 2) {
|
120 |
+
return false;
|
121 |
+
}
|
122 |
+
for (int i = 1; i < angles.length; i++) {
|
123 |
+
if (angles[i] - angles[i - 1] >= Math.PI) {
|
124 |
+
return false;
|
125 |
+
}
|
126 |
+
}
|
127 |
+
if (angles[0] - (angles[angles.length - 1] - Math.PI * 2) > Math.PI) {
|
128 |
+
return false;
|
129 |
+
}
|
130 |
+
return true;
|
131 |
+
}
|
132 |
+
|
133 |
+
static class Vec {
|
134 |
+
static final double EPS = 1e-6;
|
135 |
+
double x, y;
|
136 |
+
public Vec(double x, double y) {
|
137 |
+
this.x = x;
|
138 |
+
this.y = y;
|
139 |
+
}
|
140 |
+
public Vec add(Vec o) { return new Vec(x + o.x, y + o.y); }
|
141 |
+
public Vec sub(Vec o) { return new Vec(x - o.x, y - o.y); }
|
142 |
+
public Vec scale(double s) { return new Vec(x * s, y * s); }
|
143 |
+
public double dot(Vec o) { return x * o.x + y * o.y; }
|
144 |
+
public double cross(Vec o) { return x * o.y - y * o.x; }
|
145 |
+
public double mag2() { return dot(this); }
|
146 |
+
public double mag() { return Math.sqrt(mag2()); }
|
147 |
+
public Vec unit() { return scale(1 / mag()); }
|
148 |
+
public Vec rot90() { return new Vec(-y, x); }
|
149 |
+
public Vec rot270() { return new Vec(y, -x); }
|
150 |
+
|
151 |
+
public Vec rotate(double theta) {
|
152 |
+
double PI = Math.PI;
|
153 |
+
double newX = x * Math.cos(theta) + y * Math.cos(PI / 2 + theta);
|
154 |
+
double newY = x * Math.sin(theta) + y * Math.sin(PI / 2 + theta);
|
155 |
+
return new Vec(newX, newY);
|
156 |
+
}
|
157 |
+
|
158 |
+
// Angle between 0 and 2PI
|
159 |
+
public double angle() {
|
160 |
+
return (Math.atan2(y, x) + 2 * Math.PI) % (2 * Math.PI);
|
161 |
+
}
|
162 |
+
|
163 |
+
public String toString() {
|
164 |
+
DecimalFormat df = new DecimalFormat("#.##");
|
165 |
+
return "(" + df.format(x) + ", " + df.format(y) + ")";
|
166 |
+
}
|
167 |
+
|
168 |
+
static boolean eq(double a, double b) {
|
169 |
+
return Math.abs(a - b) < EPS;
|
170 |
+
}
|
171 |
+
|
172 |
+
static boolean leq(double a, double b) {
|
173 |
+
return a - EPS < b;
|
174 |
+
}
|
175 |
+
static boolean geq(double a, double b) {
|
176 |
+
return a + EPS > b;
|
177 |
+
}
|
178 |
+
|
179 |
+
public boolean equals(Object oo) {
|
180 |
+
Vec o = (Vec) oo;
|
181 |
+
return eq(x, o.x) && eq(y, o.y);
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
static class Seg {
|
186 |
+
Vec from, to, dir;
|
187 |
+
|
188 |
+
public Seg(Vec from, Vec to) {
|
189 |
+
this.from = from;
|
190 |
+
this.to = to;
|
191 |
+
dir = to.sub(from);
|
192 |
+
}
|
193 |
+
|
194 |
+
// Line-line intersection
|
195 |
+
public Vec lineIntersect(Seg o) {
|
196 |
+
double det = o.dir.x * dir.y - dir.x * o.dir.y;
|
197 |
+
if (Vec.eq(det, 0))
|
198 |
+
return null;
|
199 |
+
double dist = (o.dir.x * (o.from.y - from.y) - o.dir.y * (o.from.x - from.x)) / det;
|
200 |
+
return from.add(dir.scale(dist));
|
201 |
+
}
|
202 |
+
|
203 |
+
public boolean containsPoint(Vec o) {
|
204 |
+
double distFromLine = dir.unit().cross(o.sub(from));
|
205 |
+
if (!Vec.eq(distFromLine, 0)) {
|
206 |
+
return false;
|
207 |
+
}
|
208 |
+
return Vec.eq(dir.mag(), from.sub(o).mag() + to.sub(o).mag());
|
209 |
+
}
|
210 |
+
|
211 |
+
// Seg-seg intersection
|
212 |
+
public Vec segIntersection(Seg o) {
|
213 |
+
Vec intersect = lineIntersect(o);
|
214 |
+
if (intersect == null) {
|
215 |
+
return null;
|
216 |
+
}
|
217 |
+
return containsPoint(intersect) && o.containsPoint(intersect) ? intersect : null;
|
218 |
+
}
|
219 |
+
|
220 |
+
// Returns 1 if above, 0 if on, -1 if below.
|
221 |
+
public int side(Vec o) {
|
222 |
+
Vec oDir = o.sub(from);
|
223 |
+
double distFromLine = dir.unit().cross(oDir);
|
224 |
+
return Vec.eq(distFromLine, 0) ? 0 : (int)Math.signum(distFromLine);
|
225 |
+
}
|
226 |
+
|
227 |
+
public boolean intersects(Seg o) {
|
228 |
+
return side(o.from) != side(o.to) && o.side(from) != o.side(to);
|
229 |
+
}
|
230 |
+
|
231 |
+
public Vec getClosestTo(Vec o) {
|
232 |
+
double percentThere = o.sub(from).dot(dir) / dir.mag2();
|
233 |
+
return from.add(dir.scale(Math.max(0, Math.min(1, percentThere))));
|
234 |
+
}
|
235 |
+
|
236 |
+
public Vec projectToLine(Vec o) {
|
237 |
+
return dir.scale(o.sub(from).dot(dir) / dir.mag2()).add(from);
|
238 |
+
}
|
239 |
+
|
240 |
+
// Returns the shortest segment from the x-axis to the point to the y axis.
|
241 |
+
// toContain must be a point with positive x and y coordinates.
|
242 |
+
public static Seg getShortestSegFromAxesContainingQ1Point(Vec toContain) {
|
243 |
+
double slope = -Math.pow(toContain.y / toContain.x, 1.0 / 3);
|
244 |
+
double b = toContain.y - toContain.x * slope;
|
245 |
+
double xInt = -b / slope;
|
246 |
+
return new Seg(new Vec(0, b), new Vec(xInt, 0));
|
247 |
+
}
|
248 |
+
|
249 |
+
public String toString() {
|
250 |
+
return from + " -> " + to;
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
static class Circle {
|
255 |
+
Vec c;
|
256 |
+
double r;
|
257 |
+
|
258 |
+
public Circle(Vec c, double r) {
|
259 |
+
this.c = c;
|
260 |
+
this.r = r;
|
261 |
+
}
|
262 |
+
|
263 |
+
public boolean contains(Vec v) {
|
264 |
+
return c.sub(v).mag2() - Vec.EPS * Vec.EPS <= r * r;
|
265 |
+
}
|
266 |
+
|
267 |
+
// When standing at this circle, returns right tangent, then left tangent.
|
268 |
+
public Vec[] intersect(Circle o) {
|
269 |
+
if (c.equals(o.c)) {
|
270 |
+
return null;
|
271 |
+
}
|
272 |
+
Vec dir = o.c.sub(c);
|
273 |
+
double d2 = dir.mag2(), d = Math.sqrt(d2);
|
274 |
+
if (r + o.r < d || r + d < o.r || o.r + d < r) {
|
275 |
+
return null;
|
276 |
+
}
|
277 |
+
if (Vec.eq(r + o.r, d) || Vec.eq(o.r + d, r)) {
|
278 |
+
return new Vec[] {c.add(dir.scale(r / d))};
|
279 |
+
}
|
280 |
+
if (Vec.eq(r + d, o.r)) {
|
281 |
+
return new Vec[] {c.sub(dir.scale(r / d))};
|
282 |
+
}
|
283 |
+
double d1 = (r * r + d2 - o.r * o.r) / (2 * d);
|
284 |
+
double h = Math.sqrt(r * r - d1 * d1);
|
285 |
+
Vec unitDir = dir.unit();
|
286 |
+
Vec rInt = c.add(unitDir.scale(d1).add(unitDir.rot270().scale(h)));
|
287 |
+
Vec lInt = c.add(unitDir.scale(d1).add(unitDir.rot90().scale(h)));
|
288 |
+
return new Vec[] {rInt, lInt};
|
289 |
+
}
|
290 |
+
|
291 |
+
public double intersectionArea(Circle o) {
|
292 |
+
double d = o.c.sub(c).mag();
|
293 |
+
if (r + o.r < d) {
|
294 |
+
return 0;
|
295 |
+
}
|
296 |
+
double minR = Math.min(r, o.r), maxR = Math.max(r, o.r), pi = Math.PI;
|
297 |
+
if (Vec.leq(d + minR, maxR)) {
|
298 |
+
return pi * minR * minR;
|
299 |
+
}
|
300 |
+
double theta1 = 2 * Math.acos((r * r + d * d - o.r * o.r) / (2 * r * d));
|
301 |
+
double theta2 = 2 * Math.acos((o.r * o.r + d * d - r * r) / (2 * o.r * d));
|
302 |
+
double part1Area = theta1 / 2 * r * r;
|
303 |
+
double part2Area = theta2 / 2 * o.r * o.r;
|
304 |
+
double tri1 = r * r * Math.sin(theta1) / 2;
|
305 |
+
double tri2 = o.r * o.r * Math.sin(theta2) / 2;
|
306 |
+
return part1Area + part2Area - tri1 - tri2;
|
307 |
+
}
|
308 |
+
|
309 |
+
// Returns right tangent, then left tangent from perspective of the point
|
310 |
+
public Vec[] getTangentPoints(Vec p) {
|
311 |
+
if (contains(p)) {
|
312 |
+
return null;
|
313 |
+
}
|
314 |
+
double d2 = c.sub(p).mag2();
|
315 |
+
return new Circle(p, Math.sqrt(d2 - r * r)).intersect(this);
|
316 |
+
}
|
317 |
+
|
318 |
+
// Line going from my left to his right, then my right to his left lines go
|
319 |
+
// from me to him
|
320 |
+
public Seg[] internalTangentLines(Circle o) {
|
321 |
+
Vec[] tangentPoints = new Circle(c, r + o.r).getTangentPoints(o.c);
|
322 |
+
Vec offset1 = tangentPoints[0].sub(o.c).rot90().unit().scale(o.r);
|
323 |
+
Vec offset2 = tangentPoints[1].sub(o.c).rot270().unit().scale(o.r);
|
324 |
+
return new Seg[] {
|
325 |
+
new Seg(tangentPoints[0].add(offset1), o.c.add(offset1)),
|
326 |
+
new Seg(tangentPoints[1].add(offset2), o.c.add(offset2))
|
327 |
+
};
|
328 |
+
}
|
329 |
+
|
330 |
+
// Right external tangent, then left external tangent, from my perspective
|
331 |
+
// lines go from me to him
|
332 |
+
public Seg[] externalTangentLines(Circle o) {
|
333 |
+
if (o.r > r) {
|
334 |
+
Seg[] oAnswer = o.externalTangentLines(this);
|
335 |
+
return new Seg[] {
|
336 |
+
new Seg(oAnswer[1].to, oAnswer[1].from),
|
337 |
+
new Seg(oAnswer[0].to, oAnswer[0].from)
|
338 |
+
};
|
339 |
+
}
|
340 |
+
Vec[] tangentPoints = new Circle(c, r - o.r).getTangentPoints(o.c);
|
341 |
+
Vec offset1 = tangentPoints[0].sub(o.c).rot270().unit().scale(o.r);
|
342 |
+
Vec offset2 = tangentPoints[1].sub(o.c).rot90().unit().scale(o.r);
|
343 |
+
return new Seg[] {
|
344 |
+
new Seg(tangentPoints[1].add(offset2), o.c.add(offset2)),
|
345 |
+
new Seg(tangentPoints[0].add(offset1), o.c.add(offset1))
|
346 |
+
};
|
347 |
+
}
|
348 |
+
|
349 |
+
// Line (not line segment)-circle intersection in the order of line.dir
|
350 |
+
public Vec[] intersectLine(Seg line) {
|
351 |
+
Vec closest = line.projectToLine(c);
|
352 |
+
double d2 = closest.sub(c).mag2();
|
353 |
+
if (d2 > r * r) {
|
354 |
+
return null;
|
355 |
+
}
|
356 |
+
double l = Math.sqrt(r * r - d2);
|
357 |
+
if (Vec.eq(l, 0)) {
|
358 |
+
return new Vec[] {closest};
|
359 |
+
}
|
360 |
+
Vec lVec = line.dir.unit().scale(l);
|
361 |
+
return new Vec[] {closest.sub(lVec), closest.add(lVec)};
|
362 |
+
}
|
363 |
+
|
364 |
+
// Line segment-circle intersection
|
365 |
+
public Vec[] intersectSeg(Seg seg) {
|
366 |
+
Vec[] lineIntersections = intersectLine(seg);
|
367 |
+
if (lineIntersections == null)
|
368 |
+
return null;
|
369 |
+
ArrayList<Vec> contained = new ArrayList<>();
|
370 |
+
for (Vec v : lineIntersections) {
|
371 |
+
if (seg.containsPoint(v)) {
|
372 |
+
contained.add(v);
|
373 |
+
}
|
374 |
+
}
|
375 |
+
if (contained.isEmpty()) {
|
376 |
+
return null;
|
377 |
+
}
|
378 |
+
return contained.toArray(new Vec[contained.size()]);
|
379 |
+
}
|
380 |
+
|
381 |
+
public String toString() {
|
382 |
+
DecimalFormat df = new DecimalFormat();
|
383 |
+
return "center: " + c + ", r: " + df.format(r);
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
public static void main(String[] args) throws InterruptedException {
|
388 |
+
Scanner fs = new Scanner(System.in);
|
389 |
+
out = new PrintWriter(System.out);
|
390 |
+
int T = fs.nextInt();
|
391 |
+
for (int t = 1; t <= T; t++) {
|
392 |
+
solve(fs, out, t);
|
393 |
+
}
|
394 |
+
fs.close();
|
395 |
+
out.close();
|
396 |
+
}
|
397 |
+
}
|
2022/finals/cup_counterbalancing.md
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Courtney has an avant-garde kitchen counter made out of \(N\) rectangular sheets of metal of equal height, standing perpendicular to the ground. When viewed directly from the top, the counter looks like an (unfilled) polygon on a plane with \(N\) edges, the \(i\)th of which extends from point \((X_i, Y_i)\) to point \((X_{(i \text{ mod } N)+1},\, Y_{(i \text{ mod } N)+1})\). These line segments only intersect at their endpoints.
|
2 |
+
|
3 |
+
Courtney's friends often make fun of the counter, saying that the thin metal "surface" is useless for holding anything up, but Courtney wants to prove them wrong.
|
4 |
+
|
5 |
+
Courtney considers placing a cup with a circular rim of radius \(R\) onto the counter (with the rim facing down), centered at a point chosen uniformly randomly from the square \([0, L] \times [0, L]\). What is the chance that the cup stays balanced on the counter without falling? Your output will be accepted if it is within \(10^{-6}\) of the jury's answer.
|
6 |
+
|
7 |
+
*Note: The face-down cup is modeled as an unfilled ring—not as a disk.*
|
8 |
+
|
9 |
+
|
10 |
+
# Constraints
|
11 |
+
|
12 |
+
\(1 \le T \le 7\)
|
13 |
+
\(1 \le N \le 7\)
|
14 |
+
\(1 \le R, L \le 15\)
|
15 |
+
\(0 \le X_i, Y_i \le 15\)
|
16 |
+
|
17 |
+
|
18 |
+
# Input Format
|
19 |
+
|
20 |
+
Input begins with a single integer \(T\), the number of test cases. For each test case, there is first a line containing three space-separated integers \(N\), \(R\), and \(L\). Then, \(N\) lines follow, the \(i\)th of which contains two space-separated integers \(X_i\) and \(Y_i\),
|
21 |
+
|
22 |
+
|
23 |
+
# Output Format
|
24 |
+
|
25 |
+
For the \(i\)th test case, print a line containing `"Case #i: "` followed by a single real number between \(0\) and \(1\), the chance that the cup will balance if placed with its rim centered at a uniformly random point in the square \([0, L] \times [0, L]\).
|
26 |
+
|
27 |
+
|
28 |
+
# Sample Explanation
|
29 |
+
|
30 |
+
The counters in the first and second sample cases are depicted below, with the blue regions representing points at which centering the cup will lead to it staying balanced.
|
31 |
+
|
32 |
+
{{PHOTO_ID:556593865835592|WIDTH:650}}
|
33 |
+
|
34 |
+
|
2022/finals/cup_counterbalancing.out
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Case #1: 0.11696632524550592
|
2 |
+
Case #2: 0.1353446534663839
|
3 |
+
Case #3: 0.0
|
4 |
+
Case #4: 0.020000467220007968
|
5 |
+
Case #5: 0.1027849201777223
|
6 |
+
Case #6: 0.17690065571492997
|
7 |
+
Case #7: 0.03259150141335399
|
2022/finals/cup_counterbalancing_sol.md
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Let's call a position where the circle doesn't fall *stable*. First, let's see how we can check whether a given point is stable. Consider all intersection points between that cup and surrounding positions (we can find these naively in linear time). If all of these points lie on a half-circle, then the ring will fall. Otherwise, there will be three points that create a triangle which contains the center of mass of the ring.
|
2 |
+
|
3 |
+
**Solution 1:**
|
4 |
+
|
5 |
+
As it turns out, any stable point in general form (we can ignore points that are edge cases because those points are ~\(0\%\) of the area) will have at least \(3\) intersections. In fact, if a point is stable it's true that there are a particular \(3\) intersection points that make it stable. This idea is informally supported with what we'll call the "Jenga Principle": if a ring is balancing on \(4\) or more points, one of them will be "loose" in the same way a Jenga block resting on three blocks below it will always be resting on at least one "loose" block which could be removed.
|
6 |
+
|
7 |
+
We can case out all of the possible ways that two or three line segments could support a ring, brute force those segments, and then compute the overlap of these shapes. This is tricky to do mathematically for the area on which a ring could balance on two segments (the shapes include more than just circles and line segments), so some method of curve approximation will be useful here.
|
8 |
+
|
9 |
+
**Solution 2:**
|
10 |
+
|
11 |
+
Actually, if we were to just pick random points \(10^6\) times, we'll get a reasonable approximation of the answer. To get even closer, there are other tricks we can try: first, we can better distribute our points to decrease variance, such as overlaying them evenly in a grid. Once we're there, there are several options to improve our sampling, and we can follow one or more to get a solution which is accurate enough and runs in time:
|
12 |
+
|
13 |
+
- Spend less time looking at spaces that are surrounded by points that are either all stable or all unstable: Because the bounds are small, these points are very unlikely to differ from their neighbors once the neighbors are close enough.
|
14 |
+
- Use a *k*-d tree or similar data structure to break up the search space, and stop searching if large areas are \(100\%\) similar after many samples.
|
15 |
+
- Multithread our solution and optimize the constant factor overhead.
|
16 |
+
- Analyze the variance of the solution ahead of time to determine how many samples are needed for a sufficiently accurate estimate.
|
17 |
+
|
18 |
+
This optimization can be a tedious but rather straightforward process, and the main challenge is not underestimating the complexity of the potential solutions, or spending too much time on implementation. Notably, the stable region isn't necessarily convex, isn't necessarily entirely located within the polygon, isn't necessarily connected, and can even be connected but with holes.
|
2022/finals/emerald_exhibiting.cpp
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <bitset>
|
2 |
+
#include <cmath>
|
3 |
+
#include <fstream>
|
4 |
+
#include <iostream>
|
5 |
+
#include <vector>
|
6 |
+
using namespace std;
|
7 |
+
|
8 |
+
const int LIM = (int)1e9 + 1;
|
9 |
+
const bool READ_PRIMES_FROM_FILE = true;
|
10 |
+
|
11 |
+
vector<int> primes;
|
12 |
+
|
13 |
+
void load_primes() {
|
14 |
+
primes.reserve(51000000);
|
15 |
+
if (READ_PRIMES_FROM_FILE) {
|
16 |
+
ifstream fin("primes.txt");
|
17 |
+
for (int p; fin >> p;) {
|
18 |
+
primes.push_back(p);
|
19 |
+
}
|
20 |
+
} else {
|
21 |
+
bitset<LIM> sieve;
|
22 |
+
int lim = sqrt(LIM);
|
23 |
+
for (int i = 3; i < lim; i += 2) {
|
24 |
+
if (!sieve[i] && i % 2 == 1) {
|
25 |
+
for (int j = i * 2; j < LIM; j += i) {
|
26 |
+
sieve.set(j);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
}
|
30 |
+
primes.push_back(2);
|
31 |
+
for (int i = 3; i <= LIM; i += 2) {
|
32 |
+
if (!sieve[i]) {
|
33 |
+
primes.push_back(i);
|
34 |
+
}
|
35 |
+
}
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
// Returns k in the p^k term of the prime factorization of N!.
|
40 |
+
int legendre_exp(int p, int N) {
|
41 |
+
int ans = 0;
|
42 |
+
for (long long base = p; base <= N; base *= p) {
|
43 |
+
ans += N / base;
|
44 |
+
}
|
45 |
+
return ans;
|
46 |
+
}
|
47 |
+
|
48 |
+
int powmod8(int p, int exp) {
|
49 |
+
int ans = 1;
|
50 |
+
for (exp %= 8; exp > 0; exp--) {
|
51 |
+
ans = (ans * p) % 8;
|
52 |
+
}
|
53 |
+
return ans;
|
54 |
+
}
|
55 |
+
|
56 |
+
int N, K;
|
57 |
+
|
58 |
+
int solve() {
|
59 |
+
bool is_one = true, is_two = true, two_exp_even = false;
|
60 |
+
int mod8prod = 1;
|
61 |
+
for (int p : primes) {
|
62 |
+
if (p > N) {
|
63 |
+
break;
|
64 |
+
}
|
65 |
+
int exp = legendre_exp(p, N) - legendre_exp(p, K);
|
66 |
+
if (exp % 2 != 0) {
|
67 |
+
is_one = false;
|
68 |
+
}
|
69 |
+
if (p % 4 == 3 && exp % 2 == 1) {
|
70 |
+
is_two = false;
|
71 |
+
}
|
72 |
+
if (p == 2 && exp % 2 == 0) {
|
73 |
+
two_exp_even = true;
|
74 |
+
}
|
75 |
+
if (p > 2) {
|
76 |
+
mod8prod = (mod8prod * powmod8(p, exp)) % 8;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
bool is_three = !(two_exp_even && mod8prod == 7);
|
80 |
+
return is_one ? 1 : is_two ? 2 : is_three ? 3 : 4;
|
81 |
+
}
|
82 |
+
|
83 |
+
int main() {
|
84 |
+
ios_base::sync_with_stdio(false);
|
85 |
+
cin.tie(nullptr);
|
86 |
+
load_primes();
|
87 |
+
int T;
|
88 |
+
cin >> T;
|
89 |
+
for (int t = 1; t <= T; t++) {
|
90 |
+
cin >> N >> K;
|
91 |
+
cout << "Case #" << t << ": " << solve() << endl;
|
92 |
+
}
|
93 |
+
return 0;
|
94 |
+
}
|
2022/finals/emerald_exhibiting.in
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
110
|
2 |
+
1 0
|
3 |
+
2 0
|
4 |
+
3 0
|
5 |
+
4 0
|
6 |
+
5 0
|
7 |
+
6 0
|
8 |
+
7 0
|
9 |
+
8 0
|
10 |
+
9 0
|
11 |
+
10 0
|
12 |
+
1 1
|
13 |
+
2 1
|
14 |
+
3 1
|
15 |
+
4 1
|
16 |
+
5 1
|
17 |
+
6 1
|
18 |
+
7 1
|
19 |
+
8 1
|
20 |
+
9 1
|
21 |
+
10 1
|
22 |
+
2 2
|
23 |
+
3 2
|
24 |
+
4 2
|
25 |
+
5 2
|
26 |
+
6 2
|
27 |
+
7 2
|
28 |
+
8 2
|
29 |
+
9 2
|
30 |
+
10 2
|
31 |
+
3 3
|
32 |
+
4 3
|
33 |
+
5 3
|
34 |
+
6 3
|
35 |
+
7 3
|
36 |
+
8 3
|
37 |
+
9 3
|
38 |
+
10 3
|
39 |
+
4 4
|
40 |
+
5 4
|
41 |
+
6 4
|
42 |
+
7 4
|
43 |
+
8 4
|
44 |
+
9 4
|
45 |
+
10 4
|
46 |
+
5 5
|
47 |
+
6 5
|
48 |
+
7 5
|
49 |
+
8 5
|
50 |
+
9 5
|
51 |
+
10 5
|
52 |
+
6 6
|
53 |
+
7 6
|
54 |
+
8 6
|
55 |
+
9 6
|
56 |
+
10 6
|
57 |
+
7 7
|
58 |
+
8 7
|
59 |
+
9 7
|
60 |
+
10 7
|
61 |
+
8 8
|
62 |
+
9 8
|
63 |
+
10 8
|
64 |
+
9 9
|
65 |
+
10 9
|
66 |
+
10 10
|
67 |
+
28 19
|
68 |
+
19 16
|
69 |
+
151 145
|
70 |
+
100 22
|
71 |
+
99 22
|
72 |
+
19348 7362
|
73 |
+
28365 3726
|
74 |
+
81727 81723
|
75 |
+
243447 42273
|
76 |
+
283738 99824
|
77 |
+
512556 148938
|
78 |
+
550385 324141
|
79 |
+
644639 212476
|
80 |
+
677786 150413
|
81 |
+
9876322 738264
|
82 |
+
1000000000 123456789
|
83 |
+
75 71
|
84 |
+
82 79
|
85 |
+
295 287
|
86 |
+
17 10
|
87 |
+
36 22
|
88 |
+
40 4
|
89 |
+
63 58
|
90 |
+
14 6
|
91 |
+
21 13
|
92 |
+
26 19
|
93 |
+
46 16
|
94 |
+
34 14
|
95 |
+
77 8
|
96 |
+
999999992 999999990
|
97 |
+
999999958 999999956
|
98 |
+
999999915 999999913
|
99 |
+
999950885 999950883
|
100 |
+
999999963 999999960
|
101 |
+
999999982 999999979
|
102 |
+
45379 45375
|
103 |
+
49013 49007
|
104 |
+
152502 152495
|
105 |
+
961625 961619
|
106 |
+
777540 777470
|
107 |
+
50433 43257
|
108 |
+
93232 1385
|
109 |
+
33 31
|
110 |
+
85 83
|
111 |
+
285 283
|
2022/finals/emerald_exhibiting.md
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Ishiko is opening a bracelet shop. Each bracelet she plans to sell is expressed as a ring of \(N\) colored beads, with exactly \(K\) green beads made of emerald, and \(N-K\) remaining beads of all unique colors (neither green nor the same as any other bead in the bracelet). Ishiko has an infinite number of beads available for each of these \(N - K + 1\) different colors.
|
2 |
+
|
3 |
+
Ishiko wants to exhibit *one copy of every possible distinct bracelet*. Two bracelets are considered distinct if one is not a cyclic rotation of the other. For instance, the two bracelets on the left are distinct, but the two bracelets on the right are not:
|
4 |
+
|
5 |
+
{{PHOTO_ID:876374553707415|WIDTH:700}}
|
6 |
+
|
7 |
+
A vendor takes orders for triangular display cases of arbitrary positive integer heights. A case of height \(H\) has \(H\) rows, where the \(i\)th row has \(2*i - 1\) slots, each slot capable of holding one bracelet. For example, a case of height \(3\) is shown below and holds \(1 + 3 + 5 = 9\) bracelets:
|
8 |
+
|
9 |
+
{{PHOTO_ID:547949757342773|WIDTH:700}}
|
10 |
+
|
11 |
+
How many display cases (of possibly differing heights) will Ishiko need to buy to exhibit one copy of every possible bracelet *without leaving any empty slots in the display cases*?
|
12 |
+
|
13 |
+
|
14 |
+
# Constraints
|
15 |
+
|
16 |
+
\(1 \le T \le 110\)
|
17 |
+
\(1 \le N \le 10^9\)
|
18 |
+
\(0 \le K \le N\)
|
19 |
+
|
20 |
+
The sum of \(N\) across all test cases is at most \(8{,}000{,}000{,}000\).
|
21 |
+
|
22 |
+
|
23 |
+
# Input Format
|
24 |
+
|
25 |
+
Input begins with an integer \(T\), the number of cases. For each case, there is a line containing two space-separated integers, \(N\) and \(K\).
|
26 |
+
|
27 |
+
|
28 |
+
# Output Format
|
29 |
+
|
30 |
+
For the \(i\)th case, print `"Case #i: "` followed by a single integer, the minimum number of display cases that Ishiko needs to purchase to exhibit one copy of each bracelet.
|
31 |
+
|
32 |
+
|
33 |
+
# Sample Explanation
|
34 |
+
|
35 |
+
In the first sample case, let's say that Ishiko's beads are green, blue, and red. There are \(4\) possible bracelets for \(N = 5\) beads with \(K = 3\) green beads, \(1\) red bead, and \(1\) blue bead (up to rotation):
|
36 |
+
|
37 |
+
{{PHOTO_ID:1327255974690671|WIDTH:700}}
|
38 |
+
|
39 |
+
Ishiko can use a single display case of height \(2\) to display these \(4\) bracelets.
|
40 |
+
|
41 |
+
In the second sample case, let's say that Ishiko's beads are green, blue, red, and yellow. There are \(20\) possible bracelets for \(N = 6\) beads with \(K = 3\) green beads, \(1\) blue bead, \(1\) red bead, and \(1\) yellow bead. Some examples are:
|
42 |
+
|
43 |
+
{{PHOTO_ID:853886435922998|WIDTH:700}}
|
44 |
+
|
45 |
+
Ishiko can display these bracelets if she purchases a case of height \(2\) and a case of height \(4\).
|
46 |
+
|
47 |
+
In the third sample case, there are \(60\) possible bracelets and Ishiko needs at least \(4\) display cases to display all of them. One possibility is that she buys two cases of height \(1\), one case of height \(3\), and one case of height \(7\).
|
2022/finals/emerald_exhibiting.out
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Case #1: 1
|
2 |
+
Case #2: 1
|
3 |
+
Case #3: 2
|
4 |
+
Case #4: 3
|
5 |
+
Case #5: 3
|
6 |
+
Case #6: 3
|
7 |
+
Case #7: 2
|
8 |
+
Case #8: 3
|
9 |
+
Case #9: 3
|
10 |
+
Case #10: 3
|
11 |
+
Case #11: 1
|
12 |
+
Case #12: 1
|
13 |
+
Case #13: 2
|
14 |
+
Case #14: 3
|
15 |
+
Case #15: 3
|
16 |
+
Case #16: 3
|
17 |
+
Case #17: 2
|
18 |
+
Case #18: 3
|
19 |
+
Case #19: 3
|
20 |
+
Case #20: 3
|
21 |
+
Case #21: 1
|
22 |
+
Case #22: 1
|
23 |
+
Case #23: 3
|
24 |
+
Case #24: 3
|
25 |
+
Case #25: 4
|
26 |
+
Case #26: 2
|
27 |
+
Case #27: 3
|
28 |
+
Case #28: 3
|
29 |
+
Case #29: 3
|
30 |
+
Case #30: 1
|
31 |
+
Case #31: 1
|
32 |
+
Case #32: 1
|
33 |
+
Case #33: 2
|
34 |
+
Case #34: 3
|
35 |
+
Case #35: 3
|
36 |
+
Case #36: 3
|
37 |
+
Case #37: 3
|
38 |
+
Case #38: 1
|
39 |
+
Case #39: 1
|
40 |
+
Case #40: 2
|
41 |
+
Case #41: 3
|
42 |
+
Case #42: 3
|
43 |
+
Case #43: 3
|
44 |
+
Case #44: 3
|
45 |
+
Case #45: 1
|
46 |
+
Case #46: 1
|
47 |
+
Case #47: 3
|
48 |
+
Case #48: 3
|
49 |
+
Case #49: 3
|
50 |
+
Case #50: 3
|
51 |
+
Case #51: 1
|
52 |
+
Case #52: 1
|
53 |
+
Case #53: 4
|
54 |
+
Case #54: 3
|
55 |
+
Case #55: 3
|
56 |
+
Case #56: 1
|
57 |
+
Case #57: 1
|
58 |
+
Case #58: 2
|
59 |
+
Case #59: 2
|
60 |
+
Case #60: 1
|
61 |
+
Case #61: 1
|
62 |
+
Case #62: 1
|
63 |
+
Case #63: 1
|
64 |
+
Case #64: 1
|
65 |
+
Case #65: 1
|
66 |
+
Case #66: 3
|
67 |
+
Case #67: 2
|
68 |
+
Case #68: 2
|
69 |
+
Case #69: 4
|
70 |
+
Case #70: 3
|
71 |
+
Case #71: 3
|
72 |
+
Case #72: 3
|
73 |
+
Case #73: 3
|
74 |
+
Case #74: 4
|
75 |
+
Case #75: 3
|
76 |
+
Case #76: 4
|
77 |
+
Case #77: 4
|
78 |
+
Case #78: 4
|
79 |
+
Case #79: 4
|
80 |
+
Case #80: 3
|
81 |
+
Case #81: 3
|
82 |
+
Case #82: 2
|
83 |
+
Case #83: 2
|
84 |
+
Case #84: 2
|
85 |
+
Case #85: 3
|
86 |
+
Case #86: 3
|
87 |
+
Case #87: 3
|
88 |
+
Case #88: 3
|
89 |
+
Case #89: 4
|
90 |
+
Case #90: 4
|
91 |
+
Case #91: 4
|
92 |
+
Case #92: 4
|
93 |
+
Case #93: 4
|
94 |
+
Case #94: 4
|
95 |
+
Case #95: 4
|
96 |
+
Case #96: 3
|
97 |
+
Case #97: 2
|
98 |
+
Case #98: 1
|
99 |
+
Case #99: 2
|
100 |
+
Case #100: 4
|
101 |
+
Case #101: 2
|
102 |
+
Case #102: 2
|
103 |
+
Case #103: 2
|
104 |
+
Case #104: 4
|
105 |
+
Case #105: 4
|
106 |
+
Case #106: 4
|
107 |
+
Case #107: 4
|
108 |
+
Case #108: 2
|
109 |
+
Case #109: 3
|
110 |
+
Case #110: 4
|
2022/finals/emerald_exhibiting_sol.md
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
First we need to determine how many bracelets Ishiko is going to exhibit. When \(N = K\) (that is, when all of the beads are green) there is of course just \(1\) bracelet to display. Otherwise, there are \(\frac{(N-1)!}{K!}\) ways to arrange \(N\) beads in a ring when \(K\) are green beads and the rest are unique colors. Since there's always at least \(1\) unique bead, we can say that that unique bead is in a fixed position in each bracelet.
|
2 |
+
|
3 |
+
Next, we observe that a display case of height \(H\) holds exactly \(H^2\) bracelets. The problem then is to determine the minimum number of perfect squares needed to sum to \(\frac{(N-1)!}{K!}\). According to [Lagrange's four-square theorem](https://en.wikipedia.org/wiki/Lagrange%27s_four-square_theorem), we will never need more than \(4\) squares, so Ishiko only needs at most \(4\) display cases.
|
4 |
+
|
5 |
+
Let \(X\) be the number of bracelets to be displayed. As \(X\) can be as large as \(1{,}000{,}000{,}000!\), we still need a quick way to determine whether the answer is \(1\), \(2\), \(3\), or \(4\). The answer is \(1\) if \(X\) is a square number, which is something we can determine from the prime factorization of \(X\). If every prime in the factorization appears an even number of times, then \(X\) is a square number.
|
6 |
+
|
7 |
+
[Legendre's formula](https://en.wikipedia.org/wiki/Legendre%27s_formula) gives us an easy way to compute the exponent on a given prime \(p\) in the factorization of \(n!\) by summing \(\lfloor n / p^i \rfloor\) for all \(i\), which is quick since \(i\) will never be larger than \(32\) for a \(32\)-bit integer. If \(a\) is the exponent on \(p\) in \(N-1!\), and \(b\) is the exponent on \(p\) in \(K\), then the exponent on \(p\) in \(\frac{(N-1!)}{K!}\) is just \(a - b\).
|
8 |
+
|
9 |
+
How can we tell if the answer is \(2\)? Why, we can just apply the aptly-named [two-square theorem](https://en.wikipedia.org/wiki/Sum_of_two_squares_theorem), which says that \(X\) can be represented as a sum of two squares if and only if its prime decomposition contains no factor \(p^k\), where \(p \equiv 3\ (\text{mod}\ 4)\) and \(k\) is odd. Since we already have the prime factorization of \(X\), this is easy to determine.
|
10 |
+
|
11 |
+
To determine if the answer is \(3\), we'll appeal to Legendre once more. [Legendre's three-square theorem](https://en.wikipedia.org/wiki/Legendre%27s_three-square_theorem) says that \(X\) can be represented as a sum of three squares as long as it is *not* of the form \(X = 4^a(8b + 7)\), for non-negative \(a\) and \(b\). We can check if \(X\) has a factor of \(4\) by checking if the exponent on \(2\) in the prime factorization is even. If so, we can then check if \(X / 4^a \equiv 7\ (\text{mod}\ 8)\) by multiplying all prime factors higher than \(2\), modulo \(8\). Once again, \(X\) can't have more than \(32\) distinct factors as \(N\) and \(K\) are both \(32\)-bit integers, so this computation is also quick.
|
12 |
+
|
13 |
+
In the end, if the answer isn't \(1\), \(2\), or \(3\), then it must be \(4\).
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
2022/finals/hazelnut_harvesting.cpp
ADDED
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <algorithm>
|
2 |
+
#include <iostream>
|
3 |
+
#include <memory>
|
4 |
+
#include <unordered_map>
|
5 |
+
#include <unordered_set>
|
6 |
+
#include <vector>
|
7 |
+
using namespace std;
|
8 |
+
|
9 |
+
using int64 = long long;
|
10 |
+
|
11 |
+
const int MAX_COORD = 300000;
|
12 |
+
|
13 |
+
struct Rect {
|
14 |
+
int x1, y1, x2, y2, id;
|
15 |
+
int mappedX1, mappedY1, mappedX2, mappedY2;
|
16 |
+
bool ends_alive;
|
17 |
+
|
18 |
+
Rect() {}
|
19 |
+
Rect(int _x1, int _y1, int _x2, int _y2, int _id)
|
20 |
+
: x1(_x1), y1(_y1), x2(_x2), y2(_y2), id(_id) {}
|
21 |
+
|
22 |
+
bool intersects(const Rect &o) const {
|
23 |
+
return x2 >= o.x1 && x1 <= o.x2 && y1 <= o.y2 && y2 >= o.y1;
|
24 |
+
}
|
25 |
+
|
26 |
+
void merge_in(const Rect &o) {
|
27 |
+
x1 = min(x1, o.x1);
|
28 |
+
mappedX1 = min(mappedX1, o.mappedX1);
|
29 |
+
y1 = min(y1, o.y1);
|
30 |
+
mappedY1 = min(mappedY1, o.mappedY1);
|
31 |
+
x2 = max(x2, o.x2);
|
32 |
+
mappedX2 = max(mappedX2, o.mappedX2);
|
33 |
+
y2 = max(y2, o.y2);
|
34 |
+
mappedY2 = max(mappedY2, o.mappedY2);
|
35 |
+
}
|
36 |
+
|
37 |
+
bool operator <(const Rect &o) {
|
38 |
+
return id < o.id;
|
39 |
+
}
|
40 |
+
};
|
41 |
+
|
42 |
+
class InnerST {
|
43 |
+
int lo, hi, delta;
|
44 |
+
unique_ptr<InnerST> lchild, rchild;
|
45 |
+
|
46 |
+
void init_children() {
|
47 |
+
if (!lchild) {
|
48 |
+
int mid = lo + (hi - lo) / 2;
|
49 |
+
lchild = make_unique<InnerST>(lo, mid);
|
50 |
+
rchild = make_unique<InnerST>(mid + 1, hi);
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
public:
|
55 |
+
InnerST(int l, int h)
|
56 |
+
: lo(l), hi(h), delta(0), lchild(nullptr), rchild(nullptr) {}
|
57 |
+
|
58 |
+
void add(int l, int h, int d) {
|
59 |
+
if (l > hi || h < lo) {
|
60 |
+
return;
|
61 |
+
}
|
62 |
+
if (l <= lo && h >= hi) {
|
63 |
+
delta += d;
|
64 |
+
return;
|
65 |
+
}
|
66 |
+
init_children();
|
67 |
+
lchild->add(l, h, d);
|
68 |
+
rchild->add(l, h, d);
|
69 |
+
}
|
70 |
+
|
71 |
+
int query(int at) {
|
72 |
+
if (lo == hi || !lchild) {
|
73 |
+
return delta;
|
74 |
+
}
|
75 |
+
init_children();
|
76 |
+
return delta + (at <= lchild->hi ? lchild : rchild)->query(at);
|
77 |
+
}
|
78 |
+
};
|
79 |
+
|
80 |
+
class OuterST {
|
81 |
+
int lo, hi, inner_lo, inner_hi;
|
82 |
+
unique_ptr<OuterST> lchild, rchild;
|
83 |
+
InnerST inner;
|
84 |
+
|
85 |
+
public:
|
86 |
+
OuterST(int l, int h, int inner_l, int inner_h)
|
87 |
+
: lo(l),
|
88 |
+
hi(h),
|
89 |
+
inner_lo(inner_l),
|
90 |
+
inner_hi(inner_h),
|
91 |
+
inner(inner_l, inner_h) {
|
92 |
+
if (lo != hi) {
|
93 |
+
int mid = lo + (hi - lo) / 2;
|
94 |
+
lchild = make_unique<OuterST>(lo, mid, inner_lo, inner_hi);
|
95 |
+
rchild = make_unique<OuterST>(mid + 1, hi, inner_lo, inner_hi);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
// Adds a line to the inner dimension spanning inner_lo to inner_hi on
|
100 |
+
// outer_idx
|
101 |
+
void add_inner(int64 outer_idx, int inner_lo, int inner_hi) {
|
102 |
+
inner.add(inner_lo, inner_hi, 1);
|
103 |
+
if (lo != hi) {
|
104 |
+
if (outer_idx <= lchild->hi) {
|
105 |
+
lchild->add_inner(outer_idx, inner_lo, inner_hi);
|
106 |
+
} else {
|
107 |
+
rchild->add_inner(outer_idx, inner_lo, inner_hi);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
// Queries all y's that have something here.
|
113 |
+
vector<int> query_inner(int outer_lo, int outer_hi, int inner_idx) {
|
114 |
+
if (outer_lo > hi || outer_hi < lo || inner.query(inner_idx) == 0)
|
115 |
+
return {};
|
116 |
+
if (lo == hi) {
|
117 |
+
return {lo};
|
118 |
+
}
|
119 |
+
auto lres = lchild->query_inner(outer_lo, outer_hi, inner_idx);
|
120 |
+
auto rres = rchild->query_inner(outer_lo, outer_hi, inner_idx);
|
121 |
+
vector<int> sum(lres.size() + rres.size());
|
122 |
+
for (int i = 0; i < (int)sum.size(); i++) {
|
123 |
+
sum[i] = i < (int)lres.size() ? lres[i] : rres[i - lres.size()];
|
124 |
+
}
|
125 |
+
return sum;
|
126 |
+
}
|
127 |
+
|
128 |
+
void remove_inner(int outer_idx, int inner_lo, int inner_hi) {
|
129 |
+
inner.add(inner_lo, inner_hi, -1);
|
130 |
+
if (lo != hi) {
|
131 |
+
if (outer_idx <= lchild->hi) {
|
132 |
+
lchild->remove_inner(outer_idx, inner_lo, inner_hi);
|
133 |
+
} else {
|
134 |
+
rchild->remove_inner(outer_idx, inner_lo, inner_hi);
|
135 |
+
}
|
136 |
+
}
|
137 |
+
}
|
138 |
+
};
|
139 |
+
|
140 |
+
class RectHolder {
|
141 |
+
struct RectMapping {
|
142 |
+
int value;
|
143 |
+
Rect *r;
|
144 |
+
bool v1;
|
145 |
+
|
146 |
+
bool operator<(const RectMapping &r) const { return value < r.value; }
|
147 |
+
};
|
148 |
+
|
149 |
+
int sz;
|
150 |
+
vector<int64> mapsXMajor, mapsYMajor;
|
151 |
+
unordered_set<Rect*> aliveRects;
|
152 |
+
OuterST xMajorST, yMajorST;
|
153 |
+
vector<Rect*> usingXMapping, usingYMapping;
|
154 |
+
vector<int> firstOfXMajor, lastOfXMajor;
|
155 |
+
vector<int> firstOfYMajor, lastOfYMajor;
|
156 |
+
|
157 |
+
public:
|
158 |
+
RectHolder(vector<Rect> &rects)
|
159 |
+
: sz(rects.size()),
|
160 |
+
xMajorST(0, 2 * sz, 0, 2 * sz),
|
161 |
+
yMajorST(0, 2 * sz, 0, 2 * sz),
|
162 |
+
usingXMapping(2 * sz),
|
163 |
+
usingYMapping(2 * sz),
|
164 |
+
firstOfXMajor(2 * sz, (int)1e9),
|
165 |
+
lastOfXMajor(2 * sz, -1),
|
166 |
+
firstOfYMajor(2 * sz, (int)1e9),
|
167 |
+
lastOfYMajor(2 * sz, -1) {
|
168 |
+
vector<RectMapping> xMappings(2 * sz), yMappings(2 * sz);
|
169 |
+
for (int i = 0; i < sz; i++) {
|
170 |
+
xMappings[i * 2] = (RectMapping){rects[i].x1, &rects[i], true};
|
171 |
+
xMappings[i * 2 + 1] = (RectMapping){rects[i].x2, &rects[i], false};
|
172 |
+
yMappings[i * 2] = (RectMapping){rects[i].y1, &rects[i], true};
|
173 |
+
yMappings[i * 2 + 1] = (RectMapping){rects[i].y2, &rects[i], false};
|
174 |
+
}
|
175 |
+
sort(xMappings.begin(), xMappings.end());
|
176 |
+
sort(yMappings.begin(), yMappings.end());
|
177 |
+
for (int i = 0; i < (int)xMappings.size(); i++) {
|
178 |
+
usingXMapping[i] = xMappings[i].r;
|
179 |
+
usingYMapping[i] = yMappings[i].r;
|
180 |
+
if (xMappings[i].v1) {
|
181 |
+
xMappings[i].r->mappedX1 = i;
|
182 |
+
int orig = xMappings[i].r->x1;
|
183 |
+
firstOfXMajor[orig] = min(firstOfXMajor[orig], i);
|
184 |
+
lastOfXMajor[orig] = max(lastOfXMajor[orig], i);
|
185 |
+
} else {
|
186 |
+
xMappings[i].r->mappedX2 = i;
|
187 |
+
int orig = xMappings[i].r->x2;
|
188 |
+
firstOfXMajor[orig] = min(firstOfXMajor[orig], i);
|
189 |
+
lastOfXMajor[orig] = max(lastOfXMajor[orig], i);
|
190 |
+
}
|
191 |
+
if (yMappings[i].v1) {
|
192 |
+
yMappings[i].r->mappedY1 = i;
|
193 |
+
int orig = yMappings[i].r->y1;
|
194 |
+
firstOfYMajor[orig] = min(firstOfYMajor[orig], i);
|
195 |
+
lastOfYMajor[orig] = max(lastOfYMajor[orig], i);
|
196 |
+
} else {
|
197 |
+
yMappings[i].r->mappedY2 = i;
|
198 |
+
int orig = yMappings[i].r->y2;
|
199 |
+
firstOfYMajor[orig] = min(firstOfYMajor[orig], i);
|
200 |
+
lastOfYMajor[orig] = max(lastOfYMajor[orig], i);
|
201 |
+
}
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
void add_rect(Rect *r) {
|
206 |
+
aliveRects.insert(r);
|
207 |
+
usingXMapping[r->mappedX1] = r;
|
208 |
+
usingXMapping[r->mappedX2] = r;
|
209 |
+
usingYMapping[r->mappedY1] = r;
|
210 |
+
usingYMapping[r->mappedY2] = r;
|
211 |
+
xMajorST.add_inner(r->mappedX1, r->y1, r->y2);
|
212 |
+
yMajorST.add_inner(r->mappedY1, r->x1, r->x2);
|
213 |
+
xMajorST.add_inner(r->mappedX2, r->y1, r->y2);
|
214 |
+
yMajorST.add_inner(r->mappedY2, r->x1, r->x2);
|
215 |
+
}
|
216 |
+
|
217 |
+
void remove_rect(Rect *r) {
|
218 |
+
aliveRects.erase(r);
|
219 |
+
xMajorST.remove_inner(r->mappedX1, r->y1, r->y2);
|
220 |
+
yMajorST.remove_inner(r->mappedY1, r->x1, r->x2);
|
221 |
+
xMajorST.remove_inner(r->mappedX2, r->y1, r->y2);
|
222 |
+
yMajorST.remove_inner(r->mappedY2, r->x1, r->x2);
|
223 |
+
}
|
224 |
+
|
225 |
+
unordered_set<Rect*> get_alive_rect_intersecting(Rect *r) {
|
226 |
+
unordered_set<Rect*> res;
|
227 |
+
auto xsToTake1 =
|
228 |
+
xMajorST.query_inner(firstOfXMajor[r->x1], lastOfXMajor[r->x2], r->y1);
|
229 |
+
auto xsToTake2 =
|
230 |
+
xMajorST.query_inner(firstOfXMajor[r->x1], lastOfXMajor[r->x2], r->y2);
|
231 |
+
auto ysToTake1 =
|
232 |
+
yMajorST.query_inner(firstOfYMajor[r->y1], lastOfYMajor[r->y2], r->x1);
|
233 |
+
auto ysToTake2 =
|
234 |
+
yMajorST.query_inner(firstOfYMajor[r->y1], lastOfYMajor[r->y2], r->x2);
|
235 |
+
for (int x : xsToTake1) res.insert(usingXMapping[x]);
|
236 |
+
for (int x : xsToTake2) res.insert(usingXMapping[x]);
|
237 |
+
for (int y : ysToTake1) res.insert(usingYMapping[y]);
|
238 |
+
for (int y : ysToTake2) res.insert(usingYMapping[y]);
|
239 |
+
return res;
|
240 |
+
}
|
241 |
+
|
242 |
+
unordered_set<Rect*> get_all_alive_rects() {
|
243 |
+
return aliveRects;
|
244 |
+
}
|
245 |
+
};
|
246 |
+
|
247 |
+
struct Event {
|
248 |
+
int x, y1, y2;
|
249 |
+
bool adding;
|
250 |
+
Rect *r;
|
251 |
+
|
252 |
+
bool operator<(const Event &e) const {
|
253 |
+
if (x != e.x) {
|
254 |
+
return x < e.x;
|
255 |
+
}
|
256 |
+
return (y2 - y1) < (e.y2 - e.y1);
|
257 |
+
}
|
258 |
+
};
|
259 |
+
|
260 |
+
int64 solve() {
|
261 |
+
int N;
|
262 |
+
vector<Rect> rects;
|
263 |
+
vector<int> xvals, yvals;
|
264 |
+
unordered_map<int, int> x_map, y_map, x_rev, y_rev;
|
265 |
+
// Input.
|
266 |
+
cin >> N;
|
267 |
+
for (int i = 0, x, y; i < N; i++) {
|
268 |
+
cin >> x >> y;
|
269 |
+
rects.push_back(Rect(x - 1, y - 1, x + 1, y + 1, i));
|
270 |
+
xvals.push_back(x - 1);
|
271 |
+
xvals.push_back(x + 1);
|
272 |
+
yvals.push_back(y - 1);
|
273 |
+
yvals.push_back(y + 1);
|
274 |
+
}
|
275 |
+
// Compress rectangles.
|
276 |
+
sort(xvals.begin(), xvals.end());
|
277 |
+
xvals.resize(distance(xvals.begin(), unique(xvals.begin(), xvals.end())));
|
278 |
+
sort(yvals.begin(), yvals.end());
|
279 |
+
yvals.resize(distance(yvals.begin(), unique(yvals.begin(), yvals.end())));
|
280 |
+
int i = 0;
|
281 |
+
for (int x : xvals) {
|
282 |
+
x_rev[i] = x;
|
283 |
+
x_map[x] = i++;
|
284 |
+
}
|
285 |
+
i = 0;
|
286 |
+
for (int y : yvals) {
|
287 |
+
y_rev[i] = y;
|
288 |
+
y_map[y] = i++;
|
289 |
+
}
|
290 |
+
for (Rect &r : rects) {
|
291 |
+
r.x1 = x_map[r.x1];
|
292 |
+
r.y1 = y_map[r.y1];
|
293 |
+
r.x2 = x_map[r.x2];
|
294 |
+
r.y2 = y_map[r.y2];
|
295 |
+
}
|
296 |
+
// Add to rect holder.
|
297 |
+
RectHolder holder(rects);
|
298 |
+
for (Rect &to_add : rects) {
|
299 |
+
while (true) {
|
300 |
+
auto kill_now = holder.get_alive_rect_intersecting(&to_add);
|
301 |
+
if (kill_now.empty()) {
|
302 |
+
break;
|
303 |
+
}
|
304 |
+
for (Rect *to_kill : kill_now) {
|
305 |
+
holder.remove_rect(to_kill);
|
306 |
+
to_add.merge_in(*to_kill);
|
307 |
+
}
|
308 |
+
}
|
309 |
+
holder.add_rect(&to_add);
|
310 |
+
}
|
311 |
+
// Line sweep to remove any rectangles that are inside another rectangle sweep
|
312 |
+
// left to right. On an X, process bigger then smaller.
|
313 |
+
auto alive = holder.get_all_alive_rects();
|
314 |
+
InnerST st(0, MAX_COORD);
|
315 |
+
vector<Event> events;
|
316 |
+
for (Rect *r : alive) {
|
317 |
+
r->ends_alive = true;
|
318 |
+
events.push_back((Event){r->x1, r->y1, r->y2, true, r});
|
319 |
+
events.push_back((Event){r->x2, r->y1, r->y2, false, r});
|
320 |
+
}
|
321 |
+
sort(events.begin(), events.end());
|
322 |
+
for (Event &e : events) {
|
323 |
+
if (e.adding) {
|
324 |
+
if (st.query(e.y1) == 0) {
|
325 |
+
st.add(e.y1, e.y2, 1);
|
326 |
+
} else {
|
327 |
+
e.r->ends_alive = false;
|
328 |
+
}
|
329 |
+
} else {
|
330 |
+
if (e.r->ends_alive) {
|
331 |
+
st.add(e.y1, e.y2, -1);
|
332 |
+
}
|
333 |
+
}
|
334 |
+
}
|
335 |
+
// Uncompress and calculate areas.
|
336 |
+
int64 ans = 0;
|
337 |
+
for (const Rect &r : rects) {
|
338 |
+
if (r.ends_alive) {
|
339 |
+
int x1 = x_rev[r.x1], x2 = x_rev[r.x2];
|
340 |
+
int y1 = y_rev[r.y1], y2 = y_rev[r.y2];
|
341 |
+
ans += (int64)(x2 - x1) * (y2 - y1);
|
342 |
+
}
|
343 |
+
}
|
344 |
+
return ans;
|
345 |
+
}
|
346 |
+
|
347 |
+
int main() {
|
348 |
+
ios_base::sync_with_stdio(false);
|
349 |
+
cin.tie(nullptr);
|
350 |
+
int T;
|
351 |
+
cin >> T;
|
352 |
+
for (int t = 1; t <= T; t++) {
|
353 |
+
cout << "Case #" << t << ": " << solve() << endl;
|
354 |
+
}
|
355 |
+
return 0;
|
356 |
+
}
|
2022/finals/hazelnut_harvesting.in
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c3e8c58a3c7758bc0da422772c427080af5d6dc0b55036481e1a6e34cbe13e73
|
3 |
+
size 45946633
|
2022/finals/hazelnut_harvesting.md
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Boss Rob planted \(N\) happy little hazel trees in his yard (represented on a Cartesian plane). The \(i\)th tree is at integer coordinates \((X_i, Y_i)\). It's harvesting season, and Rob would like to set up some nets around the trees to collect the hazelnuts that fall.
|
2 |
+
|
3 |
+
Each net must be an axis-aligned rectangle with integer vertices (on lattice points). Rob needs at least \(1\) unit of space between nets so he can walk between them and collect the nuts. That is, nets cannot intersect, touch, or be nested. Each tree must lie strictly inside its net, i.e. must be at least \(1\) unit away from the net's edge.
|
4 |
+
|
5 |
+
Boss Rob can set up any number of nets, but would like to know the minimum total area of net required to cover all \(N\) trees.
|
6 |
+
|
7 |
+
|
8 |
+
# Constraints
|
9 |
+
|
10 |
+
\(1 \le T \le 160\)
|
11 |
+
\(1 \le N \le 800{,}000\)
|
12 |
+
\(0 \le X_i, Y_i \le 10^9\)
|
13 |
+
All \((X_i, Y_i)\) in a given test case are distinct.
|
14 |
+
|
15 |
+
\(N > 500{,}000\) in at most two test cases.
|
16 |
+
The sum of \(N\) over all test cases is at most \(4{,}000{,}000\).
|
17 |
+
|
18 |
+
|
19 |
+
# Input Format
|
20 |
+
|
21 |
+
Input begins with an integer \(T\), the number of cases. For each case, there is first a line containing a single integer \(N\). Then, \(N\) lines follow, the \(i\)th of which contains two space-separated integers \(X_i\) and \(Y_i\).
|
22 |
+
|
23 |
+
|
24 |
+
# Output Format
|
25 |
+
|
26 |
+
For the \(i\)th case, print a line containing `"Case #i: "` followed by a single integer, the minimum total area of net needed to enclose all trees according to the above requirements.
|
27 |
+
|
28 |
+
|
29 |
+
# Sample Explanation
|
30 |
+
|
31 |
+
Solutions for the first two sample cases are depicted below.
|
32 |
+
|
33 |
+
{{PHOTO_ID:2468652649959145|WIDTH:700}}
|
34 |
+
|
35 |
+
In the first case, the minimum possible net area is \(2*2 + 3*4 + 2*2 = 20\).
|
36 |
+
|
37 |
+
In the second case, the minimum possible net area is \(2*2 + 4*6 = 28\).
|
38 |
+
|
39 |
+
In the third case, it's almost possible to give each tree its own net. Unfortunately, there needs to be at least \(1\) unit of space between the nets at \((2, 2)\) so Boss Rob can walk through. This makes it indirectly necessary to use one big net to cover all trees.
|
40 |
+
|
41 |
+
{{PHOTO_ID:504150738360453|WIDTH:700}}
|
2022/finals/hazelnut_harvesting.out
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Case #1: 20
|
2 |
+
Case #2: 28
|
3 |
+
Case #3: 42
|
4 |
+
Case #4: 135
|
5 |
+
Case #5: 139
|
6 |
+
Case #6: 136
|
7 |
+
Case #7: 82
|
8 |
+
Case #8: 93
|
9 |
+
Case #9: 170
|
10 |
+
Case #10: 194
|
11 |
+
Case #11: 163
|
12 |
+
Case #12: 109
|
13 |
+
Case #13: 85
|
14 |
+
Case #14: 1000002
|
15 |
+
Case #15: 250001000001
|
16 |
+
Case #16: 1000002
|
17 |
+
Case #17: 2560000000000
|
18 |
+
Case #18: 1920000000000
|
19 |
+
Case #19: 8778
|
20 |
+
Case #20: 2643382
|
21 |
+
Case #21: 56
|
22 |
+
Case #22: 38
|
23 |
+
Case #23: 34
|
24 |
+
Case #24: 36
|
25 |
+
Case #25: 33
|
26 |
+
Case #26: 81
|
27 |
+
Case #27: 56
|
28 |
+
Case #28: 40
|
29 |
+
Case #29: 42
|
30 |
+
Case #30: 34
|
31 |
+
Case #31: 49
|
32 |
+
Case #32: 81
|
33 |
+
Case #33: 60
|
34 |
+
Case #34: 56
|
35 |
+
Case #35: 36
|
36 |
+
Case #36: 46
|
37 |
+
Case #37: 26
|
38 |
+
Case #38: 38
|
39 |
+
Case #39: 30
|
40 |
+
Case #40: 63
|
41 |
+
Case #41: 21
|
42 |
+
Case #42: 22
|
43 |
+
Case #43: 25
|
44 |
+
Case #44: 24
|
45 |
+
Case #45: 24
|
46 |
+
Case #46: 16
|
47 |
+
Case #47: 25
|
48 |
+
Case #48: 30
|
49 |
+
Case #49: 20
|
50 |
+
Case #50: 30
|
51 |
+
Case #51: 20
|
52 |
+
Case #52: 20
|
53 |
+
Case #53: 25
|
54 |
+
Case #54: 20
|
55 |
+
Case #55: 14
|
56 |
+
Case #56: 30
|
57 |
+
Case #57: 16
|
58 |
+
Case #58: 30
|
59 |
+
Case #59: 20
|
60 |
+
Case #60: 30
|
61 |
+
Case #61: 64
|
62 |
+
Case #62: 45
|
63 |
+
Case #63: 72
|
64 |
+
Case #64: 72
|
65 |
+
Case #65: 72
|
66 |
+
Case #66: 54
|
67 |
+
Case #67: 72
|
68 |
+
Case #68: 72
|
69 |
+
Case #69: 72
|
70 |
+
Case #70: 43
|
71 |
+
Case #71: 54
|
72 |
+
Case #72: 36
|
73 |
+
Case #73: 56
|
74 |
+
Case #74: 63
|
75 |
+
Case #75: 72
|
76 |
+
Case #76: 46
|
77 |
+
Case #77: 64
|
78 |
+
Case #78: 48
|
79 |
+
Case #79: 81
|
80 |
+
Case #80: 49
|
81 |
+
Case #81: 42
|
82 |
+
Case #82: 72
|
83 |
+
Case #83: 39
|
84 |
+
Case #84: 52
|
85 |
+
Case #85: 58
|
86 |
+
Case #86: 72
|
87 |
+
Case #87: 64
|
88 |
+
Case #88: 50
|
89 |
+
Case #89: 81
|
90 |
+
Case #90: 58
|
91 |
+
Case #91: 28
|
92 |
+
Case #92: 72
|
93 |
+
Case #93: 81
|
94 |
+
Case #94: 58
|
95 |
+
Case #95: 72
|
96 |
+
Case #96: 72
|
97 |
+
Case #97: 72
|
98 |
+
Case #98: 38
|
99 |
+
Case #99: 52
|
100 |
+
Case #100: 48
|
101 |
+
Case #101: 81
|
102 |
+
Case #102: 56
|
103 |
+
Case #103: 37
|
104 |
+
Case #104: 72
|
105 |
+
Case #105: 64
|
106 |
+
Case #106: 72
|
107 |
+
Case #107: 62
|
108 |
+
Case #108: 54
|
109 |
+
Case #109: 58
|
110 |
+
Case #110: 64
|
111 |
+
Case #111: 52
|
112 |
+
Case #112: 45
|
113 |
+
Case #113: 72
|
114 |
+
Case #114: 44
|
115 |
+
Case #115: 72
|
116 |
+
Case #116: 49
|
117 |
+
Case #117: 81
|
118 |
+
Case #118: 37
|
119 |
+
Case #119: 38
|
120 |
+
Case #120: 40
|
121 |
+
Case #121: 63
|
122 |
+
Case #122: 32
|
123 |
+
Case #123: 56
|
124 |
+
Case #124: 72
|
125 |
+
Case #125: 64
|
126 |
+
Case #126: 72
|
127 |
+
Case #127: 63
|
128 |
+
Case #128: 48
|
129 |
+
Case #129: 72
|
130 |
+
Case #130: 49
|
131 |
+
Case #131: 42
|
132 |
+
Case #132: 42
|
133 |
+
Case #133: 37
|
134 |
+
Case #134: 81
|
135 |
+
Case #135: 81
|
136 |
+
Case #136: 63
|
137 |
+
Case #137: 56
|
138 |
+
Case #138: 72
|
139 |
+
Case #139: 81
|
140 |
+
Case #140: 63
|
141 |
+
Case #141: 33
|
142 |
+
Case #142: 56
|
143 |
+
Case #143: 40
|
144 |
+
Case #144: 81
|
145 |
+
Case #145: 61
|
146 |
+
Case #146: 49
|
147 |
+
Case #147: 48
|
148 |
+
Case #148: 63
|
149 |
+
Case #149: 64
|
150 |
+
Case #150: 54
|
151 |
+
Case #151: 81
|
152 |
+
Case #152: 56
|
153 |
+
Case #153: 56
|
154 |
+
Case #154: 63
|
155 |
+
Case #155: 34
|
156 |
+
Case #156: 56
|
157 |
+
Case #157: 72
|
158 |
+
Case #158: 72
|
159 |
+
Case #159: 72
|
160 |
+
Case #160: 72
|
2022/finals/hazelnut_harvesting_sol.md
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
First, we'll note a greedy philosophy that if we can simply use a \(2 \times 2\) square around all trees, that’d be the best solution possible. If not, the only reason why is that some pair of these squares intersects and so we are forced to union them. It turns out there is therefore no decision making that needs to happen here; we simply must find an efficient way of simulating the unions and discovering overlapping pairs.
|
2 |
+
|
3 |
+
We can maintain a set of our current answer (the answer for some prefix), and consider the next rectangle one by one. To add rectangle \(R\) (it'll initially be a \(2 \times 2\) square, but may grow), first find all rectangles that intersect \(R\). Expand \(R\)'s boundaries to include them, and then remove them from our set, and repeat. Once we find no intersections for our expanded \(R\), add it to the set, and consider the next \(2 \times 2\) square.
|
4 |
+
|
5 |
+
To do this fast, we'll need a data structure to do the following:
|
6 |
+
|
7 |
+
- Add one rectangle to the set in \(\mathcal{O}(\log^2 N)\) time
|
8 |
+
- Remove one rectangle from the set in \(\mathcal{O}(\log^2 N)\) time
|
9 |
+
- Get all rectangles whose outline intersects a query rectangle \(R\). If there are \(s\) of these, our time complexity should be at most \(\mathcal{O}(s*\log^2 N)\). This running time is affordable because any rectangle returned here will immediately be removed, so this cost can be conceptually ignored and amortized into that subsequent removal cost.
|
10 |
+
|
11 |
+
To implement this, we'll build a helper structure: a segment tree that holds all vertical lines. It will be able to query all of the \(x\) coordinates of vertical lines that intersect a given horizontal line.
|
12 |
+
|
13 |
+
The structure consists of an outer segment tree over all \(x\)'s. For a node \(n\) in the outer segment tree which is responsible for \(x\)'s in the range \([l..r]\), node \(n\) will store an implicit segment tree that can tell us all of the \(y\)'s for which there is a vertical line with an \(x\) coordinate in \([l..r]\). To answer a query for all intersecting segments in range \([l..r]\), we can walk the outer segment tree, only going down a layer if the implicit segment tree at some node tells us that we’ll find an intersecting segment by going down that path. We can make implementation a bit faster by giving a unique ID to each rectangle’s initial borders. That way we can guarantee there’s at most one rectangle with a vertical line at any particular \(x\).
|
14 |
+
|
15 |
+
This segment tree lets us add vertical lines and query horizontal ones, so we’ll create another copy of it of add horizontal lines and query vertical ones.
|
16 |
+
|
17 |
+
Using the above operations, we can repeatedly add a rectangle and union it with any rectangles which intersect *at a border*. However, there’s still one case this doesn’t catch: it’s possible that one rectangle grows quite large and then *contains* another smaller rectangle. To handle this, we can do a simple line sweep at the end to catch any rectangles that are completely inside another. Specifically, we can sweep across \(x\)'s with an event for each rectangle’s left side (start event) and right side (end event) and maintain a segment tree of which \(y\)'s are inside a rectangle. At a start event, if we’re inside a larger rectangle, then we can mark the inner rectangle as "dead" and not add its area to the answer.
|
18 |
+
|
19 |
+
This gives us a final solution that runs in \(O(N*\log^2 N)\) time and is fast enough to solve all cases even in Java.
|
20 |
+
|
21 |
+
|
2022/finals/ml_modeling.cpp
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <algorithm>
|
2 |
+
#include <cmath>
|
3 |
+
#include <iostream>
|
4 |
+
#include <tuple>
|
5 |
+
#include <vector>
|
6 |
+
using namespace std;
|
7 |
+
|
8 |
+
const int SAMPLES = 500;
|
9 |
+
const int BOUNDS = 50;
|
10 |
+
|
11 |
+
int N;
|
12 |
+
vector<pair<double, double>> P;
|
13 |
+
|
14 |
+
inline double distsq(double dx, double dy) { return dx * dx + dy * dy; }
|
15 |
+
|
16 |
+
bool check(int x, int y, int r) {
|
17 |
+
double Rsq = r*r;
|
18 |
+
for (int i = 0; i < min(N, SAMPLES); i++) {
|
19 |
+
if (distsq(x - P[i].first, y - P[i].second) > Rsq) {
|
20 |
+
return false;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
return true;
|
24 |
+
}
|
25 |
+
|
26 |
+
void solve() {
|
27 |
+
cin >> N;
|
28 |
+
P.resize(N);
|
29 |
+
for (int i = 0; i < N; i++) {
|
30 |
+
cin >> P[i].first >> P[i].second;
|
31 |
+
}
|
32 |
+
// Generate valid circles.
|
33 |
+
vector<tuple<int, int, int>> circles;
|
34 |
+
for (int Ax = 0; Ax <= BOUNDS; Ax++) {
|
35 |
+
for (int Ay = 0; Ay <= BOUNDS; Ay++) {
|
36 |
+
int Ar = 1;
|
37 |
+
while (Ar <= BOUNDS && !check(Ax, Ay, Ar)) {
|
38 |
+
Ar++;
|
39 |
+
}
|
40 |
+
if (Ar <= BOUNDS) {
|
41 |
+
circles.push_back({Ax, Ay, Ar});
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
// Try for all valid circles.
|
46 |
+
int bestAx = -1, bestAy = -1, bestBx = -1, bestBy = -1, bestR = -1;
|
47 |
+
double bestArea = 999999;
|
48 |
+
for (int a = 0; a < (int)circles.size(); a++) {
|
49 |
+
auto [Ax, Ay, R] = circles[a];
|
50 |
+
for (int b = a + 1; b < (int)circles.size(); b++) {
|
51 |
+
auto [Bx, By, Br] = circles[b];
|
52 |
+
if (R != Br) {
|
53 |
+
continue;
|
54 |
+
}
|
55 |
+
double dsq = distsq(Ax - Bx, Ay - By);
|
56 |
+
// Fail if circles don't overlap.
|
57 |
+
if (dsq >= 4 * R * R) {
|
58 |
+
continue;
|
59 |
+
}
|
60 |
+
// Choose the answer that minimizes the area of the overlap.
|
61 |
+
double d = sqrt(dsq);
|
62 |
+
double fouradsq = sqrt((4 * R * R) - dsq);
|
63 |
+
double area = R * R * M_PI;
|
64 |
+
area -= 2 * R * R * atan2(d, fouradsq);
|
65 |
+
area -= 0.5 * d * fouradsq;
|
66 |
+
if (area < bestArea) {
|
67 |
+
bestArea = area;
|
68 |
+
bestAx = Ax;
|
69 |
+
bestAy = Ay;
|
70 |
+
bestBx = Bx;
|
71 |
+
bestBy = By;
|
72 |
+
bestR = R;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
// Compute sum of squared distance to points from both A and B.
|
77 |
+
// If B's sum is less, B is actually A.
|
78 |
+
// Note: We can afford to use all N points for this, no need to sample.
|
79 |
+
double Asum = 0, Bsum = 0;
|
80 |
+
for (auto [x, y] : P) {
|
81 |
+
Asum += distsq(x - bestAx, y - bestAy);
|
82 |
+
Bsum += distsq(x - bestBx, y - bestBy);
|
83 |
+
}
|
84 |
+
if (Bsum < Asum) {
|
85 |
+
swap(bestAx, bestBx);
|
86 |
+
swap(bestAy, bestBy);
|
87 |
+
}
|
88 |
+
cout << bestAx << " " << bestAy << " " << bestBx << " " << bestBy << " "
|
89 |
+
<< bestR << endl;
|
90 |
+
}
|
91 |
+
|
92 |
+
int main() {
|
93 |
+
ios_base::sync_with_stdio(false);
|
94 |
+
cin.tie(nullptr);
|
95 |
+
int T;
|
96 |
+
cin >> T;
|
97 |
+
for (int t = 1; t <= T; t++) {
|
98 |
+
cout << "Case #" << t << ": ";
|
99 |
+
solve();
|
100 |
+
}
|
101 |
+
return 0;
|
102 |
+
}
|
2022/finals/ml_modeling.in
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9793101756bfe31462ebbc8c026f5f60eb5ca5346502ea92faf895d3e04f3274
|
3 |
+
size 39285035
|
2022/finals/ml_modeling.md
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
You just landed a job as a machine learning engineer! As a ramp-up exercise, Boss Rob tasked you with modeling the watering wells in his yard, which can be represented on a Cartesian plane.
|
2 |
+
|
3 |
+
Boss Rob has a primary well at point \((A_x, A_y)\) and a backup well at a different point \((B_x, B_y)\), each able to water trees within an \(R\) unit radius. Using \(A_x\), \(A_y\), \(B_x\), \(B_y\), and \(R\) (unknown integers to you), Rob plants \(N\) happy little trees at real number points obtained by \(N\) calls to the function:
|
4 |
+
|
5 |
+
```
|
6 |
+
def gen_one_tree(A_x, A_y, B_x, B_y, R):
|
7 |
+
while True:
|
8 |
+
r = random.uniform(0, R)
|
9 |
+
theta = random.uniform(0, 2*math.pi)
|
10 |
+
x = A_x + r*math.cos(theta)
|
11 |
+
y = A_y + r*math.sin(theta)
|
12 |
+
if (x - B_x)**2 + (y - B_y)**2 <= R*R:
|
13 |
+
return (x, y)
|
14 |
+
```
|
15 |
+
Here, `random.uniform(L, H)` returns a real number in \([L, H)\) uniformly at random.
|
16 |
+
|
17 |
+
In other words, he picks a point \((x, y)\) in the circular range of the primary well using the special method above. If \((x, y)\) happens to be in range of the backup well, he plants a tree there (else he discards it and tries again with a new \((x, y)\)). This repeats until Rob has planted \(N\) trees.
|
18 |
+
|
19 |
+
Given only the planted tree coordinates \((X_1, Y_1), \ldots, (X_N, Y_N)\), you are tasked to predict the exact values of \(A_x\), \(A_y\), \(B_x\), \(B_y\), and \(R\). As you are new, Boss Rob will accept your solution if it correctly predicts at least \(80\%\) of the test cases.
|
20 |
+
|
21 |
+
|
22 |
+
# Constraints
|
23 |
+
|
24 |
+
\(1 \le T \le 1{,}000\)
|
25 |
+
\(500 \le N \le 1{,}000{,}000\)
|
26 |
+
\(0 \le A_x, A_y, B_x, B_y \le 50\)
|
27 |
+
\((A_x, A_y) \ne (B_x, B_y)\)
|
28 |
+
\(1 \le R \le 50\)
|
29 |
+
The sum of \(N\) across all test cases is at most \(2{,}000{,}000\).
|
30 |
+
|
31 |
+
The intersection area of the two circular regions is strictly positive.
|
32 |
+
|
33 |
+
Tree coordinates in the data were truly generated using the randomized algorithm as described above. The secret parameters \(A_x\), \(A_y\), \(B_x\), \(B_y\), and \(R\) have also been chosen uniformly at random for each case (rejecting cases where the circles are identical or do not have positive overlap).
|
34 |
+
|
35 |
+
|
36 |
+
# Input Format
|
37 |
+
|
38 |
+
Input begins with a single integer \(T\), the number of test cases. For each case, there is first a line containing a single integer \(N\), the number of planted trees. Then, \(N\) lines follow, the \(i\)th of which contains two space-separated real numbers \(X_i\) and \(Y_i\), each given to \(6\) decimal places.
|
39 |
+
|
40 |
+
|
41 |
+
# Output Format
|
42 |
+
|
43 |
+
For the \(i\)th test case, print a line containing `"Case #i: "`, followed by the five space-separated integers \(A_x\), \(A_y\), \(B_x\), \(B_y\), and \(R\), in that order.
|
44 |
+
|
45 |
+
|
46 |
+
# Sample Explanation
|
47 |
+
|
48 |
+
The first sample case is pictured below, with the primary well's range in red, the backup well's range in blue, and the \(500\) randomly-generated trees in green:
|
49 |
+
|
50 |
+
{{PHOTO_ID:6502772429739994|WIDTH:700}}
|
51 |
+
|
2022/finals/ml_modeling.out
ADDED
@@ -0,0 +1,1000 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Case #1: 30 35 31 14 46
|
2 |
+
Case #2: 46 11 39 5 46
|
3 |
+
Case #3: 18 26 20 16 35
|
4 |
+
Case #4: 15 45 1 1 43
|
5 |
+
Case #5: 37 48 46 27 21
|
6 |
+
Case #6: 14 31 49 30 35
|
7 |
+
Case #7: 27 39 14 36 11
|
8 |
+
Case #8: 32 40 16 50 28
|
9 |
+
Case #9: 16 12 26 14 12
|
10 |
+
Case #10: 50 11 48 24 48
|
11 |
+
Case #11: 21 14 17 39 24
|
12 |
+
Case #12: 22 12 49 24 30
|
13 |
+
Case #13: 30 10 1 43 29
|
14 |
+
Case #14: 33 28 38 10 40
|
15 |
+
Case #15: 30 8 21 31 18
|
16 |
+
Case #16: 38 34 32 25 23
|
17 |
+
Case #17: 24 44 46 29 43
|
18 |
+
Case #18: 4 1 42 11 22
|
19 |
+
Case #19: 6 40 23 3 36
|
20 |
+
Case #20: 49 17 9 6 26
|
21 |
+
Case #21: 34 17 36 5 45
|
22 |
+
Case #22: 15 21 20 38 12
|
23 |
+
Case #23: 0 35 34 28 23
|
24 |
+
Case #24: 7 25 40 8 46
|
25 |
+
Case #25: 11 43 40 6 48
|
26 |
+
Case #26: 2 44 50 28 30
|
27 |
+
Case #27: 19 18 20 17 28
|
28 |
+
Case #28: 18 33 26 27 24
|
29 |
+
Case #29: 37 13 6 16 42
|
30 |
+
Case #30: 16 2 28 12 43
|
31 |
+
Case #31: 25 44 11 48 18
|
32 |
+
Case #32: 39 21 46 11 18
|
33 |
+
Case #33: 14 18 11 29 11
|
34 |
+
Case #34: 35 0 42 5 22
|
35 |
+
Case #35: 45 24 47 11 26
|
36 |
+
Case #36: 22 26 30 31 5
|
37 |
+
Case #37: 44 6 24 8 27
|
38 |
+
Case #38: 17 30 16 29 38
|
39 |
+
Case #39: 45 49 21 23 26
|
40 |
+
Case #40: 43 7 9 0 29
|
41 |
+
Case #41: 10 12 8 46 34
|
42 |
+
Case #42: 29 33 21 15 28
|
43 |
+
Case #43: 10 2 29 49 45
|
44 |
+
Case #44: 12 36 49 48 37
|
45 |
+
Case #45: 47 40 12 16 48
|
46 |
+
Case #46: 41 26 20 48 23
|
47 |
+
Case #47: 36 25 15 15 26
|
48 |
+
Case #48: 36 15 28 43 18
|
49 |
+
Case #49: 28 42 37 4 29
|
50 |
+
Case #50: 41 6 40 43 32
|
51 |
+
Case #51: 33 33 25 9 37
|
52 |
+
Case #52: 33 30 28 9 32
|
53 |
+
Case #53: 47 11 33 24 11
|
54 |
+
Case #54: 25 45 11 46 25
|
55 |
+
Case #55: 16 15 2 49 38
|
56 |
+
Case #56: 42 35 2 43 22
|
57 |
+
Case #57: 12 0 26 7 26
|
58 |
+
Case #58: 24 36 27 4 27
|
59 |
+
Case #59: 34 44 33 37 19
|
60 |
+
Case #60: 48 34 13 44 48
|
61 |
+
Case #61: 38 28 50 44 15
|
62 |
+
Case #62: 50 36 38 50 29
|
63 |
+
Case #63: 18 31 41 30 37
|
64 |
+
Case #64: 22 0 38 25 22
|
65 |
+
Case #65: 47 48 34 20 45
|
66 |
+
Case #66: 35 49 24 42 21
|
67 |
+
Case #67: 27 40 39 25 46
|
68 |
+
Case #68: 17 1 20 15 28
|
69 |
+
Case #69: 2 20 41 46 45
|
70 |
+
Case #70: 23 30 24 23 4
|
71 |
+
Case #71: 37 36 4 11 39
|
72 |
+
Case #72: 37 44 28 44 39
|
73 |
+
Case #73: 26 19 4 36 40
|
74 |
+
Case #74: 40 43 48 41 37
|
75 |
+
Case #75: 9 35 26 43 35
|
76 |
+
Case #76: 8 4 44 29 23
|
77 |
+
Case #77: 15 5 22 34 20
|
78 |
+
Case #78: 2 24 33 26 47
|
79 |
+
Case #79: 6 45 27 6 47
|
80 |
+
Case #80: 47 40 24 6 24
|
81 |
+
Case #81: 46 5 41 41 23
|
82 |
+
Case #82: 8 14 38 1 25
|
83 |
+
Case #83: 26 50 21 39 30
|
84 |
+
Case #84: 49 44 0 1 49
|
85 |
+
Case #85: 19 32 40 48 25
|
86 |
+
Case #86: 35 22 42 21 30
|
87 |
+
Case #87: 50 17 3 18 44
|
88 |
+
Case #88: 45 43 23 11 43
|
89 |
+
Case #89: 0 39 0 15 35
|
90 |
+
Case #90: 8 15 32 46 38
|
91 |
+
Case #91: 15 2 47 35 38
|
92 |
+
Case #92: 10 9 26 12 16
|
93 |
+
Case #93: 21 15 15 15 45
|
94 |
+
Case #94: 50 41 4 12 38
|
95 |
+
Case #95: 21 41 44 50 50
|
96 |
+
Case #96: 33 32 47 17 23
|
97 |
+
Case #97: 32 20 28 10 7
|
98 |
+
Case #98: 35 49 45 24 37
|
99 |
+
Case #99: 24 26 45 48 33
|
100 |
+
Case #100: 23 13 34 40 39
|
101 |
+
Case #101: 40 20 27 7 21
|
102 |
+
Case #102: 0 33 1 8 33
|
103 |
+
Case #103: 30 16 19 26 27
|
104 |
+
Case #104: 22 49 49 42 47
|
105 |
+
Case #105: 9 40 13 5 26
|
106 |
+
Case #106: 16 26 12 8 36
|
107 |
+
Case #107: 12 12 7 45 44
|
108 |
+
Case #108: 26 50 13 21 41
|
109 |
+
Case #109: 9 38 39 1 47
|
110 |
+
Case #110: 14 6 32 40 34
|
111 |
+
Case #111: 34 45 25 14 44
|
112 |
+
Case #112: 28 35 46 42 21
|
113 |
+
Case #113: 25 23 2 23 45
|
114 |
+
Case #114: 29 38 14 42 12
|
115 |
+
Case #115: 25 25 20 8 33
|
116 |
+
Case #116: 16 39 47 1 41
|
117 |
+
Case #117: 44 16 29 32 29
|
118 |
+
Case #118: 30 5 46 19 28
|
119 |
+
Case #119: 48 13 17 28 35
|
120 |
+
Case #120: 35 15 5 1 24
|
121 |
+
Case #121: 19 18 31 31 32
|
122 |
+
Case #122: 35 11 14 23 36
|
123 |
+
Case #123: 45 24 20 49 21
|
124 |
+
Case #124: 20 41 38 50 16
|
125 |
+
Case #125: 22 11 16 40 18
|
126 |
+
Case #126: 48 46 26 43 50
|
127 |
+
Case #127: 28 11 36 13 40
|
128 |
+
Case #128: 12 50 1 48 22
|
129 |
+
Case #129: 15 34 19 5 40
|
130 |
+
Case #130: 32 36 9 27 44
|
131 |
+
Case #131: 5 48 43 14 50
|
132 |
+
Case #132: 15 32 44 22 36
|
133 |
+
Case #133: 8 42 12 40 24
|
134 |
+
Case #134: 38 7 50 0 47
|
135 |
+
Case #135: 21 15 25 12 43
|
136 |
+
Case #136: 43 35 45 4 41
|
137 |
+
Case #137: 38 24 29 3 14
|
138 |
+
Case #138: 1 26 4 4 35
|
139 |
+
Case #139: 7 50 27 45 11
|
140 |
+
Case #140: 45 33 46 16 19
|
141 |
+
Case #141: 45 38 37 44 37
|
142 |
+
Case #142: 12 32 38 40 34
|
143 |
+
Case #143: 33 1 29 30 50
|
144 |
+
Case #144: 26 27 50 31 22
|
145 |
+
Case #145: 3 0 25 16 18
|
146 |
+
Case #146: 25 17 2 34 18
|
147 |
+
Case #147: 30 20 33 20 40
|
148 |
+
Case #148: 6 34 17 30 26
|
149 |
+
Case #149: 30 10 3 20 28
|
150 |
+
Case #150: 2 15 33 6 26
|
151 |
+
Case #151: 8 43 13 42 26
|
152 |
+
Case #152: 14 44 3 48 26
|
153 |
+
Case #153: 42 50 41 24 31
|
154 |
+
Case #154: 28 11 37 46 38
|
155 |
+
Case #155: 6 4 39 16 50
|
156 |
+
Case #156: 28 12 35 46 21
|
157 |
+
Case #157: 50 37 14 28 39
|
158 |
+
Case #158: 10 24 6 9 46
|
159 |
+
Case #159: 0 18 9 32 35
|
160 |
+
Case #160: 17 38 15 37 24
|
161 |
+
Case #161: 48 41 10 0 29
|
162 |
+
Case #162: 37 6 11 14 32
|
163 |
+
Case #163: 50 47 30 47 34
|
164 |
+
Case #164: 25 42 26 4 33
|
165 |
+
Case #165: 10 16 17 19 20
|
166 |
+
Case #166: 46 16 9 10 27
|
167 |
+
Case #167: 20 44 38 23 26
|
168 |
+
Case #168: 4 41 48 43 39
|
169 |
+
Case #169: 28 44 17 47 9
|
170 |
+
Case #170: 39 25 4 46 33
|
171 |
+
Case #171: 1 15 38 7 21
|
172 |
+
Case #172: 8 25 41 47 25
|
173 |
+
Case #173: 3 9 32 3 45
|
174 |
+
Case #174: 36 4 24 29 30
|
175 |
+
Case #175: 10 39 21 39 38
|
176 |
+
Case #176: 8 42 18 49 46
|
177 |
+
Case #177: 13 48 27 32 35
|
178 |
+
Case #178: 19 4 18 23 31
|
179 |
+
Case #179: 1 40 29 48 17
|
180 |
+
Case #180: 31 21 31 48 18
|
181 |
+
Case #181: 17 24 40 15 35
|
182 |
+
Case #182: 2 8 28 2 45
|
183 |
+
Case #183: 5 15 35 33 26
|
184 |
+
Case #184: 27 21 26 0 36
|
185 |
+
Case #185: 14 39 28 39 33
|
186 |
+
Case #186: 23 14 11 22 46
|
187 |
+
Case #187: 48 47 1 28 34
|
188 |
+
Case #188: 34 47 12 16 33
|
189 |
+
Case #189: 22 47 24 39 45
|
190 |
+
Case #190: 20 9 13 21 48
|
191 |
+
Case #191: 6 49 27 39 50
|
192 |
+
Case #192: 38 4 25 16 21
|
193 |
+
Case #193: 25 0 4 17 47
|
194 |
+
Case #194: 19 4 42 11 32
|
195 |
+
Case #195: 50 47 32 31 32
|
196 |
+
Case #196: 30 36 12 1 25
|
197 |
+
Case #197: 40 40 34 41 40
|
198 |
+
Case #198: 4 45 50 38 49
|
199 |
+
Case #199: 42 39 50 39 8
|
200 |
+
Case #200: 19 38 35 19 40
|
201 |
+
Case #201: 49 3 15 18 44
|
202 |
+
Case #202: 35 42 35 38 31
|
203 |
+
Case #203: 29 50 40 4 47
|
204 |
+
Case #204: 22 37 33 46 38
|
205 |
+
Case #205: 44 18 4 10 31
|
206 |
+
Case #206: 49 9 16 48 47
|
207 |
+
Case #207: 25 32 22 3 49
|
208 |
+
Case #208: 3 21 25 3 46
|
209 |
+
Case #209: 18 24 20 20 36
|
210 |
+
Case #210: 20 48 37 44 22
|
211 |
+
Case #211: 32 25 40 9 21
|
212 |
+
Case #212: 9 46 14 39 48
|
213 |
+
Case #213: 29 29 41 3 30
|
214 |
+
Case #214: 17 49 23 40 6
|
215 |
+
Case #215: 45 29 46 9 19
|
216 |
+
Case #216: 13 33 5 13 43
|
217 |
+
Case #217: 10 27 36 39 20
|
218 |
+
Case #218: 2 19 22 25 45
|
219 |
+
Case #219: 2 32 42 28 39
|
220 |
+
Case #220: 41 10 31 29 21
|
221 |
+
Case #221: 28 9 44 23 49
|
222 |
+
Case #222: 12 10 5 3 30
|
223 |
+
Case #223: 15 27 42 0 41
|
224 |
+
Case #224: 10 16 16 32 27
|
225 |
+
Case #225: 12 4 20 38 37
|
226 |
+
Case #226: 36 36 12 18 22
|
227 |
+
Case #227: 33 5 25 8 42
|
228 |
+
Case #228: 44 26 28 25 38
|
229 |
+
Case #229: 48 22 32 11 25
|
230 |
+
Case #230: 9 44 11 49 22
|
231 |
+
Case #231: 6 48 21 44 25
|
232 |
+
Case #232: 29 44 44 9 44
|
233 |
+
Case #233: 21 19 31 20 25
|
234 |
+
Case #234: 50 25 29 32 21
|
235 |
+
Case #235: 27 11 30 3 40
|
236 |
+
Case #236: 16 48 32 32 22
|
237 |
+
Case #237: 6 5 35 32 24
|
238 |
+
Case #238: 14 44 19 32 41
|
239 |
+
Case #239: 19 13 48 10 31
|
240 |
+
Case #240: 2 1 32 41 46
|
241 |
+
Case #241: 8 39 12 21 40
|
242 |
+
Case #242: 13 45 10 37 37
|
243 |
+
Case #243: 4 23 11 41 22
|
244 |
+
Case #244: 10 21 7 32 13
|
245 |
+
Case #245: 11 1 10 15 43
|
246 |
+
Case #246: 32 42 21 10 29
|
247 |
+
Case #247: 39 27 12 38 41
|
248 |
+
Case #248: 43 48 36 47 36
|
249 |
+
Case #249: 37 37 48 32 32
|
250 |
+
Case #250: 37 49 1 46 21
|
251 |
+
Case #251: 26 11 46 7 44
|
252 |
+
Case #252: 47 9 48 15 50
|
253 |
+
Case #253: 29 47 19 8 40
|
254 |
+
Case #254: 21 31 40 35 16
|
255 |
+
Case #255: 39 31 46 27 11
|
256 |
+
Case #256: 1 10 8 2 48
|
257 |
+
Case #257: 42 37 5 22 40
|
258 |
+
Case #258: 34 33 17 39 30
|
259 |
+
Case #259: 31 4 28 17 17
|
260 |
+
Case #260: 1 30 44 36 48
|
261 |
+
Case #261: 6 3 29 8 41
|
262 |
+
Case #262: 21 16 18 46 30
|
263 |
+
Case #263: 23 10 42 42 37
|
264 |
+
Case #264: 19 3 4 3 32
|
265 |
+
Case #265: 36 24 36 9 24
|
266 |
+
Case #266: 49 1 27 4 13
|
267 |
+
Case #267: 23 22 29 33 29
|
268 |
+
Case #268: 18 38 21 41 45
|
269 |
+
Case #269: 1 47 4 2 30
|
270 |
+
Case #270: 47 34 44 7 25
|
271 |
+
Case #271: 41 34 26 1 22
|
272 |
+
Case #272: 28 4 28 27 37
|
273 |
+
Case #273: 46 44 39 19 49
|
274 |
+
Case #274: 36 20 30 8 12
|
275 |
+
Case #275: 43 40 35 36 41
|
276 |
+
Case #276: 26 48 9 20 18
|
277 |
+
Case #277: 23 46 15 14 49
|
278 |
+
Case #278: 34 14 50 18 39
|
279 |
+
Case #279: 31 0 29 7 33
|
280 |
+
Case #280: 49 16 43 29 24
|
281 |
+
Case #281: 12 3 38 14 16
|
282 |
+
Case #282: 22 25 30 39 22
|
283 |
+
Case #283: 27 0 30 28 34
|
284 |
+
Case #284: 8 10 48 6 50
|
285 |
+
Case #285: 10 20 43 40 26
|
286 |
+
Case #286: 17 11 19 8 36
|
287 |
+
Case #287: 27 40 16 27 25
|
288 |
+
Case #288: 38 25 21 35 14
|
289 |
+
Case #289: 49 25 20 31 49
|
290 |
+
Case #290: 20 49 42 45 50
|
291 |
+
Case #291: 17 7 1 17 43
|
292 |
+
Case #292: 7 48 14 42 7
|
293 |
+
Case #293: 29 39 4 48 48
|
294 |
+
Case #294: 36 40 27 42 40
|
295 |
+
Case #295: 16 39 17 15 13
|
296 |
+
Case #296: 8 39 37 46 30
|
297 |
+
Case #297: 15 29 13 3 16
|
298 |
+
Case #298: 27 46 9 35 21
|
299 |
+
Case #299: 9 3 14 36 41
|
300 |
+
Case #300: 1 47 8 12 29
|
301 |
+
Case #301: 15 27 30 5 38
|
302 |
+
Case #302: 21 8 3 22 49
|
303 |
+
Case #303: 23 45 25 28 11
|
304 |
+
Case #304: 9 4 8 3 11
|
305 |
+
Case #305: 7 3 1 26 33
|
306 |
+
Case #306: 21 23 23 11 43
|
307 |
+
Case #307: 40 46 35 21 50
|
308 |
+
Case #308: 38 41 39 39 19
|
309 |
+
Case #309: 8 29 14 3 25
|
310 |
+
Case #310: 23 10 11 24 16
|
311 |
+
Case #311: 2 17 20 26 44
|
312 |
+
Case #312: 43 20 7 1 30
|
313 |
+
Case #313: 7 33 27 25 26
|
314 |
+
Case #314: 29 44 18 43 28
|
315 |
+
Case #315: 14 21 8 31 34
|
316 |
+
Case #316: 36 32 2 6 39
|
317 |
+
Case #317: 10 27 34 17 37
|
318 |
+
Case #318: 44 34 22 42 38
|
319 |
+
Case #319: 21 37 49 46 17
|
320 |
+
Case #320: 4 31 15 45 47
|
321 |
+
Case #321: 45 44 39 47 11
|
322 |
+
Case #322: 21 20 35 8 38
|
323 |
+
Case #323: 48 27 43 12 41
|
324 |
+
Case #324: 32 25 38 11 13
|
325 |
+
Case #325: 22 45 16 23 31
|
326 |
+
Case #326: 32 39 6 22 24
|
327 |
+
Case #327: 5 40 10 16 34
|
328 |
+
Case #328: 46 13 26 7 26
|
329 |
+
Case #329: 49 48 46 29 10
|
330 |
+
Case #330: 47 18 35 41 40
|
331 |
+
Case #331: 35 35 41 15 44
|
332 |
+
Case #332: 8 23 12 34 13
|
333 |
+
Case #333: 18 47 30 25 22
|
334 |
+
Case #334: 46 15 14 41 36
|
335 |
+
Case #335: 4 45 14 0 48
|
336 |
+
Case #336: 28 20 17 23 49
|
337 |
+
Case #337: 24 11 6 28 21
|
338 |
+
Case #338: 38 27 18 37 28
|
339 |
+
Case #339: 28 40 7 14 20
|
340 |
+
Case #340: 11 17 2 43 40
|
341 |
+
Case #341: 47 45 13 26 36
|
342 |
+
Case #342: 20 4 14 34 16
|
343 |
+
Case #343: 33 5 14 18 42
|
344 |
+
Case #344: 2 21 21 33 23
|
345 |
+
Case #345: 5 36 20 32 24
|
346 |
+
Case #346: 4 29 23 49 46
|
347 |
+
Case #347: 12 38 14 20 44
|
348 |
+
Case #348: 5 15 35 5 32
|
349 |
+
Case #349: 20 45 38 46 25
|
350 |
+
Case #350: 3 30 6 50 47
|
351 |
+
Case #351: 25 46 14 38 37
|
352 |
+
Case #352: 49 50 19 46 33
|
353 |
+
Case #353: 31 34 41 38 18
|
354 |
+
Case #354: 30 11 12 43 26
|
355 |
+
Case #355: 27 8 33 23 23
|
356 |
+
Case #356: 37 37 1 16 50
|
357 |
+
Case #357: 46 47 16 21 26
|
358 |
+
Case #358: 36 16 5 34 41
|
359 |
+
Case #359: 27 39 21 48 18
|
360 |
+
Case #360: 15 37 21 48 47
|
361 |
+
Case #361: 14 36 38 24 49
|
362 |
+
Case #362: 48 41 6 32 36
|
363 |
+
Case #363: 45 11 40 1 11
|
364 |
+
Case #364: 35 20 0 9 39
|
365 |
+
Case #365: 19 44 42 30 49
|
366 |
+
Case #366: 25 3 30 5 38
|
367 |
+
Case #367: 49 26 45 23 50
|
368 |
+
Case #368: 35 39 37 40 32
|
369 |
+
Case #369: 29 19 26 37 37
|
370 |
+
Case #370: 43 15 48 23 17
|
371 |
+
Case #371: 7 9 15 31 30
|
372 |
+
Case #372: 22 21 39 17 45
|
373 |
+
Case #373: 38 45 3 15 39
|
374 |
+
Case #374: 12 42 13 30 35
|
375 |
+
Case #375: 39 39 44 4 23
|
376 |
+
Case #376: 13 46 33 45 37
|
377 |
+
Case #377: 13 22 15 19 43
|
378 |
+
Case #378: 10 11 20 21 11
|
379 |
+
Case #379: 28 25 24 10 45
|
380 |
+
Case #380: 26 41 6 29 33
|
381 |
+
Case #381: 13 27 1 39 10
|
382 |
+
Case #382: 12 34 16 5 31
|
383 |
+
Case #383: 8 19 24 5 37
|
384 |
+
Case #384: 49 27 48 4 43
|
385 |
+
Case #385: 7 0 31 6 39
|
386 |
+
Case #386: 50 44 29 42 47
|
387 |
+
Case #387: 47 21 44 5 49
|
388 |
+
Case #388: 6 20 19 42 31
|
389 |
+
Case #389: 39 37 16 13 50
|
390 |
+
Case #390: 31 26 26 21 45
|
391 |
+
Case #391: 48 29 35 30 21
|
392 |
+
Case #392: 9 20 18 19 18
|
393 |
+
Case #393: 45 48 4 38 48
|
394 |
+
Case #394: 36 6 43 33 40
|
395 |
+
Case #395: 7 19 44 0 28
|
396 |
+
Case #396: 28 43 14 48 27
|
397 |
+
Case #397: 43 21 47 6 11
|
398 |
+
Case #398: 3 0 6 20 29
|
399 |
+
Case #399: 10 28 8 1 41
|
400 |
+
Case #400: 27 25 49 46 21
|
401 |
+
Case #401: 48 23 14 17 27
|
402 |
+
Case #402: 38 24 22 15 34
|
403 |
+
Case #403: 6 50 1 48 15
|
404 |
+
Case #404: 7 24 23 7 16
|
405 |
+
Case #405: 36 39 13 23 17
|
406 |
+
Case #406: 50 7 42 23 13
|
407 |
+
Case #407: 46 14 38 0 20
|
408 |
+
Case #408: 29 36 27 50 32
|
409 |
+
Case #409: 4 11 28 23 37
|
410 |
+
Case #410: 11 29 37 16 35
|
411 |
+
Case #411: 21 21 19 39 19
|
412 |
+
Case #412: 13 37 27 50 32
|
413 |
+
Case #413: 23 10 29 23 42
|
414 |
+
Case #414: 15 40 23 30 20
|
415 |
+
Case #415: 16 21 35 35 42
|
416 |
+
Case #416: 15 6 5 34 24
|
417 |
+
Case #417: 16 38 27 2 43
|
418 |
+
Case #418: 50 16 45 48 25
|
419 |
+
Case #419: 19 26 45 25 31
|
420 |
+
Case #420: 42 41 8 46 40
|
421 |
+
Case #421: 7 17 6 16 4
|
422 |
+
Case #422: 26 35 41 33 41
|
423 |
+
Case #423: 22 34 37 9 31
|
424 |
+
Case #424: 49 44 37 14 25
|
425 |
+
Case #425: 34 6 23 34 23
|
426 |
+
Case #426: 26 48 50 17 26
|
427 |
+
Case #427: 48 28 8 18 43
|
428 |
+
Case #428: 2 39 6 14 47
|
429 |
+
Case #429: 14 28 26 29 24
|
430 |
+
Case #430: 43 44 17 41 48
|
431 |
+
Case #431: 26 18 36 7 21
|
432 |
+
Case #432: 0 1 7 31 18
|
433 |
+
Case #433: 13 42 29 19 40
|
434 |
+
Case #434: 20 35 13 6 22
|
435 |
+
Case #435: 0 35 11 40 19
|
436 |
+
Case #436: 32 43 50 23 32
|
437 |
+
Case #437: 43 11 10 18 32
|
438 |
+
Case #438: 6 2 8 11 7
|
439 |
+
Case #439: 36 10 29 30 29
|
440 |
+
Case #440: 42 27 25 33 32
|
441 |
+
Case #441: 33 6 14 42 27
|
442 |
+
Case #442: 39 36 49 20 12
|
443 |
+
Case #443: 27 46 23 39 11
|
444 |
+
Case #444: 32 1 10 35 48
|
445 |
+
Case #445: 42 34 36 37 50
|
446 |
+
Case #446: 18 18 8 22 15
|
447 |
+
Case #447: 18 31 23 32 4
|
448 |
+
Case #448: 31 2 41 15 40
|
449 |
+
Case #449: 37 5 30 9 33
|
450 |
+
Case #450: 20 33 16 43 13
|
451 |
+
Case #451: 10 18 35 27 44
|
452 |
+
Case #452: 44 42 48 15 22
|
453 |
+
Case #453: 31 45 50 24 23
|
454 |
+
Case #454: 17 45 41 22 34
|
455 |
+
Case #455: 22 28 5 1 20
|
456 |
+
Case #456: 42 49 2 13 43
|
457 |
+
Case #457: 27 17 20 24 43
|
458 |
+
Case #458: 4 18 22 19 35
|
459 |
+
Case #459: 6 28 3 43 32
|
460 |
+
Case #460: 7 21 3 27 45
|
461 |
+
Case #461: 26 46 20 21 49
|
462 |
+
Case #462: 48 16 4 32 48
|
463 |
+
Case #463: 1 26 26 35 14
|
464 |
+
Case #464: 24 50 46 11 26
|
465 |
+
Case #465: 36 45 39 31 26
|
466 |
+
Case #466: 20 19 20 27 32
|
467 |
+
Case #467: 40 23 38 29 38
|
468 |
+
Case #468: 13 24 37 38 44
|
469 |
+
Case #469: 26 43 2 24 43
|
470 |
+
Case #470: 16 9 24 10 22
|
471 |
+
Case #471: 22 30 49 6 44
|
472 |
+
Case #472: 28 20 30 13 30
|
473 |
+
Case #473: 20 2 34 19 25
|
474 |
+
Case #474: 21 17 40 15 12
|
475 |
+
Case #475: 0 36 14 43 26
|
476 |
+
Case #476: 12 7 48 37 31
|
477 |
+
Case #477: 9 4 27 6 17
|
478 |
+
Case #478: 14 30 2 31 34
|
479 |
+
Case #479: 33 39 28 35 46
|
480 |
+
Case #480: 42 45 27 28 47
|
481 |
+
Case #481: 12 32 45 11 43
|
482 |
+
Case #482: 50 45 29 44 18
|
483 |
+
Case #483: 49 44 34 25 47
|
484 |
+
Case #484: 46 33 9 34 46
|
485 |
+
Case #485: 6 4 7 3 10
|
486 |
+
Case #486: 19 26 29 32 47
|
487 |
+
Case #487: 38 5 4 9 36
|
488 |
+
Case #488: 27 42 24 35 9
|
489 |
+
Case #489: 30 41 43 2 31
|
490 |
+
Case #490: 24 12 33 14 25
|
491 |
+
Case #491: 36 8 20 12 29
|
492 |
+
Case #492: 19 22 12 26 44
|
493 |
+
Case #493: 43 3 31 9 13
|
494 |
+
Case #494: 42 16 48 21 34
|
495 |
+
Case #495: 38 11 22 39 30
|
496 |
+
Case #496: 18 45 16 41 31
|
497 |
+
Case #497: 1 21 28 32 25
|
498 |
+
Case #498: 37 7 29 30 27
|
499 |
+
Case #499: 18 43 2 21 40
|
500 |
+
Case #500: 29 24 31 4 42
|
501 |
+
Case #501: 14 15 17 8 4
|
502 |
+
Case #502: 36 1 41 19 34
|
503 |
+
Case #503: 39 13 39 49 48
|
504 |
+
Case #504: 31 50 32 31 20
|
505 |
+
Case #505: 12 25 3 20 12
|
506 |
+
Case #506: 16 17 39 0 29
|
507 |
+
Case #507: 13 7 38 32 31
|
508 |
+
Case #508: 40 41 10 44 18
|
509 |
+
Case #509: 6 33 2 13 21
|
510 |
+
Case #510: 7 3 29 22 26
|
511 |
+
Case #511: 3 7 33 21 38
|
512 |
+
Case #512: 38 15 8 44 23
|
513 |
+
Case #513: 18 46 23 45 39
|
514 |
+
Case #514: 29 20 50 24 27
|
515 |
+
Case #515: 47 5 21 24 48
|
516 |
+
Case #516: 6 6 37 33 33
|
517 |
+
Case #517: 23 49 30 14 37
|
518 |
+
Case #518: 27 24 6 36 31
|
519 |
+
Case #519: 40 19 17 10 45
|
520 |
+
Case #520: 10 29 15 6 18
|
521 |
+
Case #521: 43 10 21 43 32
|
522 |
+
Case #522: 27 3 48 26 17
|
523 |
+
Case #523: 34 37 50 27 24
|
524 |
+
Case #524: 14 10 9 12 41
|
525 |
+
Case #525: 27 11 50 42 25
|
526 |
+
Case #526: 31 8 25 22 25
|
527 |
+
Case #527: 18 46 36 15 32
|
528 |
+
Case #528: 35 50 19 27 18
|
529 |
+
Case #529: 8 10 4 1 45
|
530 |
+
Case #530: 16 1 41 17 50
|
531 |
+
Case #531: 11 41 35 45 43
|
532 |
+
Case #532: 26 8 32 17 49
|
533 |
+
Case #533: 0 47 11 10 21
|
534 |
+
Case #534: 17 30 26 39 21
|
535 |
+
Case #535: 48 24 23 9 34
|
536 |
+
Case #536: 35 0 23 3 23
|
537 |
+
Case #537: 29 28 26 9 31
|
538 |
+
Case #538: 14 13 47 44 46
|
539 |
+
Case #539: 34 16 26 31 40
|
540 |
+
Case #540: 22 43 27 36 30
|
541 |
+
Case #541: 43 14 5 28 44
|
542 |
+
Case #542: 6 19 27 22 19
|
543 |
+
Case #543: 34 36 27 6 41
|
544 |
+
Case #544: 7 35 16 26 23
|
545 |
+
Case #545: 24 10 11 22 42
|
546 |
+
Case #546: 50 50 40 0 30
|
547 |
+
Case #547: 44 22 25 8 44
|
548 |
+
Case #548: 16 42 10 34 7
|
549 |
+
Case #549: 35 18 24 37 19
|
550 |
+
Case #550: 3 36 1 8 23
|
551 |
+
Case #551: 38 6 4 8 32
|
552 |
+
Case #552: 14 32 2 16 47
|
553 |
+
Case #553: 34 5 33 30 23
|
554 |
+
Case #554: 49 4 42 12 15
|
555 |
+
Case #555: 37 4 36 24 49
|
556 |
+
Case #556: 15 7 30 29 47
|
557 |
+
Case #557: 45 8 23 17 26
|
558 |
+
Case #558: 18 7 34 29 19
|
559 |
+
Case #559: 25 31 4 33 24
|
560 |
+
Case #560: 50 47 36 21 36
|
561 |
+
Case #561: 47 41 33 45 39
|
562 |
+
Case #562: 33 16 13 0 39
|
563 |
+
Case #563: 14 37 26 49 9
|
564 |
+
Case #564: 32 5 31 13 35
|
565 |
+
Case #565: 40 6 24 46 30
|
566 |
+
Case #566: 44 27 15 46 30
|
567 |
+
Case #567: 32 25 23 9 13
|
568 |
+
Case #568: 47 6 30 8 25
|
569 |
+
Case #569: 16 29 23 40 24
|
570 |
+
Case #570: 23 23 6 36 36
|
571 |
+
Case #571: 25 40 15 7 47
|
572 |
+
Case #572: 26 8 36 34 49
|
573 |
+
Case #573: 41 19 2 0 46
|
574 |
+
Case #574: 38 37 46 15 14
|
575 |
+
Case #575: 38 23 11 36 15
|
576 |
+
Case #576: 35 24 32 42 48
|
577 |
+
Case #577: 46 35 47 26 19
|
578 |
+
Case #578: 12 36 6 22 34
|
579 |
+
Case #579: 2 26 14 38 24
|
580 |
+
Case #580: 49 23 36 15 13
|
581 |
+
Case #581: 9 15 48 29 36
|
582 |
+
Case #582: 32 21 9 9 27
|
583 |
+
Case #583: 30 0 8 23 25
|
584 |
+
Case #584: 27 16 47 25 19
|
585 |
+
Case #585: 19 32 3 10 27
|
586 |
+
Case #586: 14 35 9 45 43
|
587 |
+
Case #587: 35 33 4 27 21
|
588 |
+
Case #588: 23 2 4 46 34
|
589 |
+
Case #589: 13 3 19 41 40
|
590 |
+
Case #590: 14 9 48 9 32
|
591 |
+
Case #591: 5 3 3 17 39
|
592 |
+
Case #592: 25 29 33 27 11
|
593 |
+
Case #593: 16 14 19 21 15
|
594 |
+
Case #594: 22 10 1 14 19
|
595 |
+
Case #595: 36 13 1 39 22
|
596 |
+
Case #596: 43 28 26 13 38
|
597 |
+
Case #597: 26 32 27 46 43
|
598 |
+
Case #598: 23 6 33 22 11
|
599 |
+
Case #599: 48 21 21 38 38
|
600 |
+
Case #600: 42 33 48 24 33
|
601 |
+
Case #601: 2 36 20 43 15
|
602 |
+
Case #602: 5 11 47 4 34
|
603 |
+
Case #603: 2 0 28 37 50
|
604 |
+
Case #604: 30 30 50 13 18
|
605 |
+
Case #605: 21 26 37 3 31
|
606 |
+
Case #606: 27 9 35 12 7
|
607 |
+
Case #607: 41 9 20 38 45
|
608 |
+
Case #608: 48 31 7 20 35
|
609 |
+
Case #609: 3 9 28 1 30
|
610 |
+
Case #610: 34 17 42 26 39
|
611 |
+
Case #611: 20 19 16 6 23
|
612 |
+
Case #612: 41 38 16 26 23
|
613 |
+
Case #613: 28 22 15 35 38
|
614 |
+
Case #614: 12 7 20 28 13
|
615 |
+
Case #615: 9 48 33 19 21
|
616 |
+
Case #616: 21 39 8 39 44
|
617 |
+
Case #617: 26 0 37 16 47
|
618 |
+
Case #618: 37 49 24 30 15
|
619 |
+
Case #619: 30 36 11 42 40
|
620 |
+
Case #620: 18 27 22 43 22
|
621 |
+
Case #621: 7 31 26 21 11
|
622 |
+
Case #622: 0 24 5 28 46
|
623 |
+
Case #623: 0 29 26 1 43
|
624 |
+
Case #624: 40 24 40 14 41
|
625 |
+
Case #625: 19 33 50 12 44
|
626 |
+
Case #626: 0 31 24 4 44
|
627 |
+
Case #627: 35 24 35 5 47
|
628 |
+
Case #628: 13 43 26 17 33
|
629 |
+
Case #629: 48 28 43 38 18
|
630 |
+
Case #630: 17 12 49 39 40
|
631 |
+
Case #631: 26 14 38 44 48
|
632 |
+
Case #632: 32 26 16 23 35
|
633 |
+
Case #633: 28 11 18 47 39
|
634 |
+
Case #634: 17 0 41 36 47
|
635 |
+
Case #635: 19 20 24 38 10
|
636 |
+
Case #636: 0 15 24 32 30
|
637 |
+
Case #637: 6 33 0 26 44
|
638 |
+
Case #638: 5 18 5 11 18
|
639 |
+
Case #639: 26 44 50 36 45
|
640 |
+
Case #640: 3 41 47 31 25
|
641 |
+
Case #641: 35 17 26 46 42
|
642 |
+
Case #642: 1 31 27 12 45
|
643 |
+
Case #643: 3 28 21 13 15
|
644 |
+
Case #644: 11 34 8 37 3
|
645 |
+
Case #645: 35 31 22 13 20
|
646 |
+
Case #646: 10 8 13 43 34
|
647 |
+
Case #647: 3 22 46 17 44
|
648 |
+
Case #648: 30 23 35 15 22
|
649 |
+
Case #649: 8 20 40 30 39
|
650 |
+
Case #650: 12 11 16 32 24
|
651 |
+
Case #651: 26 44 35 43 47
|
652 |
+
Case #652: 16 47 31 49 20
|
653 |
+
Case #653: 8 11 49 21 35
|
654 |
+
Case #654: 44 12 0 8 24
|
655 |
+
Case #655: 21 22 41 24 14
|
656 |
+
Case #656: 3 35 43 3 30
|
657 |
+
Case #657: 1 24 5 48 34
|
658 |
+
Case #658: 15 13 22 28 15
|
659 |
+
Case #659: 2 17 8 17 9
|
660 |
+
Case #660: 8 49 13 39 34
|
661 |
+
Case #661: 20 8 32 22 41
|
662 |
+
Case #662: 2 29 27 43 25
|
663 |
+
Case #663: 3 10 2 17 43
|
664 |
+
Case #664: 6 47 43 50 30
|
665 |
+
Case #665: 38 43 35 40 32
|
666 |
+
Case #666: 19 14 33 19 31
|
667 |
+
Case #667: 24 47 4 23 26
|
668 |
+
Case #668: 37 38 0 44 23
|
669 |
+
Case #669: 23 29 42 18 46
|
670 |
+
Case #670: 22 24 41 14 32
|
671 |
+
Case #671: 9 28 39 30 38
|
672 |
+
Case #672: 14 24 7 17 27
|
673 |
+
Case #673: 26 7 23 42 29
|
674 |
+
Case #674: 14 25 36 31 26
|
675 |
+
Case #675: 2 11 31 31 40
|
676 |
+
Case #676: 18 1 35 15 39
|
677 |
+
Case #677: 1 21 35 50 36
|
678 |
+
Case #678: 32 44 34 24 44
|
679 |
+
Case #679: 13 42 19 38 43
|
680 |
+
Case #680: 14 50 1 33 44
|
681 |
+
Case #681: 0 6 2 22 21
|
682 |
+
Case #682: 15 0 28 45 43
|
683 |
+
Case #683: 20 27 32 32 27
|
684 |
+
Case #684: 11 21 14 21 18
|
685 |
+
Case #685: 21 39 20 32 49
|
686 |
+
Case #686: 32 45 0 5 30
|
687 |
+
Case #687: 31 36 38 4 44
|
688 |
+
Case #688: 44 5 30 13 10
|
689 |
+
Case #689: 46 37 11 49 42
|
690 |
+
Case #690: 37 47 42 26 30
|
691 |
+
Case #691: 12 46 13 23 19
|
692 |
+
Case #692: 33 16 27 4 9
|
693 |
+
Case #693: 26 18 19 39 49
|
694 |
+
Case #694: 26 8 44 45 31
|
695 |
+
Case #695: 7 10 28 15 17
|
696 |
+
Case #696: 44 41 40 30 47
|
697 |
+
Case #697: 20 10 49 18 17
|
698 |
+
Case #698: 17 23 45 20 22
|
699 |
+
Case #699: 44 12 14 2 29
|
700 |
+
Case #700: 28 29 19 4 26
|
701 |
+
Case #701: 35 8 30 15 17
|
702 |
+
Case #702: 18 26 50 25 19
|
703 |
+
Case #703: 50 9 46 41 18
|
704 |
+
Case #704: 29 38 49 13 43
|
705 |
+
Case #705: 1 43 20 20 20
|
706 |
+
Case #706: 34 34 10 22 30
|
707 |
+
Case #707: 38 7 46 15 20
|
708 |
+
Case #708: 3 4 29 2 17
|
709 |
+
Case #709: 28 19 42 1 46
|
710 |
+
Case #710: 34 11 23 13 9
|
711 |
+
Case #711: 27 16 42 16 36
|
712 |
+
Case #712: 40 46 46 48 7
|
713 |
+
Case #713: 29 19 7 44 38
|
714 |
+
Case #714: 41 22 32 2 16
|
715 |
+
Case #715: 33 21 24 32 11
|
716 |
+
Case #716: 48 41 41 10 31
|
717 |
+
Case #717: 17 18 17 7 29
|
718 |
+
Case #718: 39 9 13 31 44
|
719 |
+
Case #719: 14 33 44 22 28
|
720 |
+
Case #720: 45 26 39 23 11
|
721 |
+
Case #721: 21 8 7 44 34
|
722 |
+
Case #722: 33 25 34 37 26
|
723 |
+
Case #723: 24 49 24 27 35
|
724 |
+
Case #724: 12 35 19 12 40
|
725 |
+
Case #725: 8 31 16 9 23
|
726 |
+
Case #726: 6 7 33 47 48
|
727 |
+
Case #727: 37 9 29 9 25
|
728 |
+
Case #728: 13 13 5 13 38
|
729 |
+
Case #729: 8 19 41 32 39
|
730 |
+
Case #730: 43 12 46 12 21
|
731 |
+
Case #731: 36 38 41 2 36
|
732 |
+
Case #732: 22 43 20 32 48
|
733 |
+
Case #733: 38 22 39 19 34
|
734 |
+
Case #734: 26 13 37 27 12
|
735 |
+
Case #735: 42 46 49 37 40
|
736 |
+
Case #736: 5 21 41 1 36
|
737 |
+
Case #737: 44 9 47 15 29
|
738 |
+
Case #738: 49 31 42 25 14
|
739 |
+
Case #739: 33 10 0 43 32
|
740 |
+
Case #740: 1 28 24 31 44
|
741 |
+
Case #741: 28 4 13 9 35
|
742 |
+
Case #742: 10 41 11 5 41
|
743 |
+
Case #743: 45 19 24 42 42
|
744 |
+
Case #744: 8 28 5 18 34
|
745 |
+
Case #745: 35 1 25 4 50
|
746 |
+
Case #746: 50 19 14 34 28
|
747 |
+
Case #747: 47 8 47 23 29
|
748 |
+
Case #748: 25 14 42 10 36
|
749 |
+
Case #749: 9 11 36 39 27
|
750 |
+
Case #750: 36 44 35 11 30
|
751 |
+
Case #751: 32 2 25 24 21
|
752 |
+
Case #752: 9 42 31 28 43
|
753 |
+
Case #753: 28 29 1 40 15
|
754 |
+
Case #754: 37 48 9 11 41
|
755 |
+
Case #755: 47 32 12 7 28
|
756 |
+
Case #756: 30 19 19 34 14
|
757 |
+
Case #757: 44 33 30 4 48
|
758 |
+
Case #758: 23 46 36 33 49
|
759 |
+
Case #759: 11 37 10 28 23
|
760 |
+
Case #760: 5 24 29 33 19
|
761 |
+
Case #761: 23 28 21 42 28
|
762 |
+
Case #762: 11 23 28 19 36
|
763 |
+
Case #763: 10 26 8 46 42
|
764 |
+
Case #764: 20 31 50 18 32
|
765 |
+
Case #765: 11 11 15 31 44
|
766 |
+
Case #766: 50 21 41 18 49
|
767 |
+
Case #767: 1 47 41 13 49
|
768 |
+
Case #768: 33 45 31 22 50
|
769 |
+
Case #769: 41 46 28 13 45
|
770 |
+
Case #770: 1 14 49 35 32
|
771 |
+
Case #771: 19 0 10 45 32
|
772 |
+
Case #772: 21 10 45 8 27
|
773 |
+
Case #773: 32 8 40 24 20
|
774 |
+
Case #774: 7 29 27 25 20
|
775 |
+
Case #775: 28 5 10 50 42
|
776 |
+
Case #776: 24 24 28 48 13
|
777 |
+
Case #777: 3 12 18 33 41
|
778 |
+
Case #778: 39 35 31 50 41
|
779 |
+
Case #779: 40 9 18 8 27
|
780 |
+
Case #780: 30 29 11 27 10
|
781 |
+
Case #781: 47 40 17 50 39
|
782 |
+
Case #782: 23 1 43 43 33
|
783 |
+
Case #783: 20 50 30 42 23
|
784 |
+
Case #784: 17 45 28 37 33
|
785 |
+
Case #785: 27 41 47 42 30
|
786 |
+
Case #786: 20 12 6 47 44
|
787 |
+
Case #787: 10 18 31 41 37
|
788 |
+
Case #788: 20 7 31 9 19
|
789 |
+
Case #789: 4 2 11 4 11
|
790 |
+
Case #790: 25 21 3 8 16
|
791 |
+
Case #791: 20 8 4 42 38
|
792 |
+
Case #792: 4 12 12 39 37
|
793 |
+
Case #793: 40 19 34 40 16
|
794 |
+
Case #794: 22 13 28 31 31
|
795 |
+
Case #795: 43 13 6 44 46
|
796 |
+
Case #796: 42 39 34 34 40
|
797 |
+
Case #797: 21 3 16 23 34
|
798 |
+
Case #798: 29 49 7 40 22
|
799 |
+
Case #799: 44 1 11 43 28
|
800 |
+
Case #800: 48 24 26 30 39
|
801 |
+
Case #801: 48 16 20 18 19
|
802 |
+
Case #802: 16 37 13 27 38
|
803 |
+
Case #803: 21 12 5 12 49
|
804 |
+
Case #804: 18 12 7 21 38
|
805 |
+
Case #805: 1 29 12 41 49
|
806 |
+
Case #806: 34 5 26 19 12
|
807 |
+
Case #807: 1 27 14 16 46
|
808 |
+
Case #808: 5 13 10 37 13
|
809 |
+
Case #809: 41 19 29 21 16
|
810 |
+
Case #810: 4 7 42 45 37
|
811 |
+
Case #811: 7 22 19 5 11
|
812 |
+
Case #812: 19 9 38 19 13
|
813 |
+
Case #813: 6 9 12 31 21
|
814 |
+
Case #814: 22 13 10 10 29
|
815 |
+
Case #815: 14 20 35 14 34
|
816 |
+
Case #816: 22 48 10 9 26
|
817 |
+
Case #817: 43 31 25 26 21
|
818 |
+
Case #818: 4 29 21 49 40
|
819 |
+
Case #819: 37 21 7 10 50
|
820 |
+
Case #820: 17 37 43 36 21
|
821 |
+
Case #821: 30 5 34 15 33
|
822 |
+
Case #822: 20 3 11 23 15
|
823 |
+
Case #823: 11 46 38 0 36
|
824 |
+
Case #824: 44 30 7 3 50
|
825 |
+
Case #825: 15 39 22 14 23
|
826 |
+
Case #826: 15 27 31 14 30
|
827 |
+
Case #827: 12 1 10 33 46
|
828 |
+
Case #828: 33 37 40 35 37
|
829 |
+
Case #829: 36 37 49 19 15
|
830 |
+
Case #830: 38 30 0 8 33
|
831 |
+
Case #831: 47 33 35 30 12
|
832 |
+
Case #832: 29 25 33 38 18
|
833 |
+
Case #833: 26 15 4 3 24
|
834 |
+
Case #834: 24 14 36 35 36
|
835 |
+
Case #835: 9 5 22 7 35
|
836 |
+
Case #836: 47 41 17 50 29
|
837 |
+
Case #837: 21 21 29 24 26
|
838 |
+
Case #838: 10 8 17 10 41
|
839 |
+
Case #839: 29 27 24 20 19
|
840 |
+
Case #840: 30 15 17 42 26
|
841 |
+
Case #841: 1 22 15 25 41
|
842 |
+
Case #842: 19 42 6 18 46
|
843 |
+
Case #843: 15 6 3 18 17
|
844 |
+
Case #844: 32 13 48 18 18
|
845 |
+
Case #845: 30 30 5 23 42
|
846 |
+
Case #846: 47 38 34 12 38
|
847 |
+
Case #847: 34 47 41 6 26
|
848 |
+
Case #848: 8 30 17 7 37
|
849 |
+
Case #849: 48 36 1 3 37
|
850 |
+
Case #850: 43 44 37 37 49
|
851 |
+
Case #851: 19 42 27 2 26
|
852 |
+
Case #852: 47 33 33 11 49
|
853 |
+
Case #853: 20 45 39 29 18
|
854 |
+
Case #854: 20 11 29 38 32
|
855 |
+
Case #855: 31 50 22 37 20
|
856 |
+
Case #856: 23 5 39 12 32
|
857 |
+
Case #857: 16 32 4 27 32
|
858 |
+
Case #858: 36 15 47 24 27
|
859 |
+
Case #859: 13 25 7 50 30
|
860 |
+
Case #860: 29 32 45 33 24
|
861 |
+
Case #861: 38 11 5 6 42
|
862 |
+
Case #862: 38 39 49 29 43
|
863 |
+
Case #863: 39 16 47 27 42
|
864 |
+
Case #864: 46 19 49 24 38
|
865 |
+
Case #865: 37 29 46 41 10
|
866 |
+
Case #866: 49 42 32 36 34
|
867 |
+
Case #867: 44 50 24 18 29
|
868 |
+
Case #868: 2 12 12 29 46
|
869 |
+
Case #869: 46 27 37 0 46
|
870 |
+
Case #870: 47 50 27 26 19
|
871 |
+
Case #871: 37 17 33 45 17
|
872 |
+
Case #872: 44 21 47 35 15
|
873 |
+
Case #873: 10 32 22 38 27
|
874 |
+
Case #874: 12 49 17 0 25
|
875 |
+
Case #875: 3 41 7 50 29
|
876 |
+
Case #876: 43 12 32 28 29
|
877 |
+
Case #877: 29 24 49 13 39
|
878 |
+
Case #878: 33 9 46 8 50
|
879 |
+
Case #879: 17 32 23 28 37
|
880 |
+
Case #880: 21 18 16 12 15
|
881 |
+
Case #881: 24 50 22 0 45
|
882 |
+
Case #882: 8 2 12 20 23
|
883 |
+
Case #883: 47 31 27 31 15
|
884 |
+
Case #884: 35 24 26 22 38
|
885 |
+
Case #885: 24 9 0 35 26
|
886 |
+
Case #886: 16 47 44 40 42
|
887 |
+
Case #887: 8 49 47 27 40
|
888 |
+
Case #888: 21 43 2 20 45
|
889 |
+
Case #889: 22 50 1 0 43
|
890 |
+
Case #890: 21 16 30 5 10
|
891 |
+
Case #891: 45 22 18 42 44
|
892 |
+
Case #892: 49 44 47 11 37
|
893 |
+
Case #893: 0 23 46 30 35
|
894 |
+
Case #894: 23 31 41 40 36
|
895 |
+
Case #895: 34 42 8 8 25
|
896 |
+
Case #896: 13 10 6 20 34
|
897 |
+
Case #897: 38 5 15 30 38
|
898 |
+
Case #898: 4 0 48 3 47
|
899 |
+
Case #899: 42 0 10 27 31
|
900 |
+
Case #900: 9 17 16 48 19
|
901 |
+
Case #901: 8 18 15 28 9
|
902 |
+
Case #902: 5 38 1 33 6
|
903 |
+
Case #903: 0 29 19 21 26
|
904 |
+
Case #904: 38 37 37 12 40
|
905 |
+
Case #905: 8 5 39 29 35
|
906 |
+
Case #906: 31 23 38 42 30
|
907 |
+
Case #907: 18 50 50 4 33
|
908 |
+
Case #908: 50 12 41 25 25
|
909 |
+
Case #909: 28 18 36 1 13
|
910 |
+
Case #910: 26 24 1 0 47
|
911 |
+
Case #911: 28 40 12 41 42
|
912 |
+
Case #912: 0 49 19 20 38
|
913 |
+
Case #913: 40 26 37 6 42
|
914 |
+
Case #914: 33 49 12 43 30
|
915 |
+
Case #915: 16 15 43 1 22
|
916 |
+
Case #916: 17 45 14 14 23
|
917 |
+
Case #917: 11 20 12 24 23
|
918 |
+
Case #918: 8 40 38 9 27
|
919 |
+
Case #919: 45 1 45 43 33
|
920 |
+
Case #920: 49 33 2 33 43
|
921 |
+
Case #921: 18 28 18 11 44
|
922 |
+
Case #922: 9 9 17 38 27
|
923 |
+
Case #923: 17 45 6 19 45
|
924 |
+
Case #924: 20 35 4 29 27
|
925 |
+
Case #925: 2 11 15 10 41
|
926 |
+
Case #926: 34 34 24 28 30
|
927 |
+
Case #927: 22 25 28 3 33
|
928 |
+
Case #928: 15 7 19 17 18
|
929 |
+
Case #929: 29 36 9 24 24
|
930 |
+
Case #930: 4 0 25 31 26
|
931 |
+
Case #931: 44 23 3 26 25
|
932 |
+
Case #932: 27 7 12 15 46
|
933 |
+
Case #933: 10 44 1 25 30
|
934 |
+
Case #934: 34 45 46 49 11
|
935 |
+
Case #935: 19 22 15 7 39
|
936 |
+
Case #936: 27 48 38 42 29
|
937 |
+
Case #937: 20 42 19 34 23
|
938 |
+
Case #938: 12 26 45 4 46
|
939 |
+
Case #939: 36 46 40 44 8
|
940 |
+
Case #940: 47 34 39 23 31
|
941 |
+
Case #941: 38 23 32 43 40
|
942 |
+
Case #942: 23 44 9 24 41
|
943 |
+
Case #943: 41 9 1 33 34
|
944 |
+
Case #944: 15 30 37 28 38
|
945 |
+
Case #945: 36 38 42 21 45
|
946 |
+
Case #946: 13 39 22 6 42
|
947 |
+
Case #947: 0 10 41 23 47
|
948 |
+
Case #948: 0 4 50 50 43
|
949 |
+
Case #949: 3 39 15 27 11
|
950 |
+
Case #950: 38 13 45 48 20
|
951 |
+
Case #951: 2 43 3 41 40
|
952 |
+
Case #952: 40 4 15 2 24
|
953 |
+
Case #953: 8 35 28 31 49
|
954 |
+
Case #954: 45 20 46 9 45
|
955 |
+
Case #955: 29 1 21 0 20
|
956 |
+
Case #956: 46 17 9 0 40
|
957 |
+
Case #957: 19 40 30 35 39
|
958 |
+
Case #958: 13 34 19 36 21
|
959 |
+
Case #959: 47 8 37 10 34
|
960 |
+
Case #960: 33 42 0 17 27
|
961 |
+
Case #961: 47 38 38 50 34
|
962 |
+
Case #962: 38 11 25 20 18
|
963 |
+
Case #963: 24 13 29 19 48
|
964 |
+
Case #964: 47 48 16 11 50
|
965 |
+
Case #965: 42 27 17 34 34
|
966 |
+
Case #966: 20 30 36 15 30
|
967 |
+
Case #967: 3 1 33 20 32
|
968 |
+
Case #968: 14 40 27 36 16
|
969 |
+
Case #969: 38 4 35 18 14
|
970 |
+
Case #970: 12 40 41 29 42
|
971 |
+
Case #971: 18 32 26 16 26
|
972 |
+
Case #972: 44 21 39 33 42
|
973 |
+
Case #973: 5 8 16 19 13
|
974 |
+
Case #974: 12 10 18 10 23
|
975 |
+
Case #975: 37 44 13 21 28
|
976 |
+
Case #976: 27 5 23 0 12
|
977 |
+
Case #977: 35 7 29 25 29
|
978 |
+
Case #978: 20 44 20 43 15
|
979 |
+
Case #979: 29 42 13 19 31
|
980 |
+
Case #980: 1 12 41 41 50
|
981 |
+
Case #981: 10 26 33 31 43
|
982 |
+
Case #982: 35 8 39 24 16
|
983 |
+
Case #983: 3 47 17 41 34
|
984 |
+
Case #984: 28 2 14 28 41
|
985 |
+
Case #985: 17 44 16 21 29
|
986 |
+
Case #986: 17 2 10 15 28
|
987 |
+
Case #987: 2 12 18 12 48
|
988 |
+
Case #988: 0 47 18 33 40
|
989 |
+
Case #989: 22 38 22 13 23
|
990 |
+
Case #990: 7 17 38 40 25
|
991 |
+
Case #991: 46 12 40 13 7
|
992 |
+
Case #992: 3 38 50 19 28
|
993 |
+
Case #993: 15 30 23 46 38
|
994 |
+
Case #994: 12 31 11 33 29
|
995 |
+
Case #995: 45 19 45 38 26
|
996 |
+
Case #996: 34 16 8 23 43
|
997 |
+
Case #997: 29 15 20 11 36
|
998 |
+
Case #998: 36 18 35 5 7
|
999 |
+
Case #999: 40 43 18 11 25
|
1000 |
+
Case #1000: 19 6 18 8 29
|
2022/finals/ml_modeling_sol.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
There are many ways you might approach this problem, but a simple one is to find the pair of circles that contain all the given points while minimizing the area of the intersection.
|
2 |
+
|
3 |
+
A naive solution tries all ~\(50^5\) possible pairs of circles and does an \(O(N)\) check to confirm that all of the points lie in the intersection of that pair of circles. Even if we downsample to \(500\) points (the minimum guaranteed by the problem), that's still too slow.
|
4 |
+
|
5 |
+
We can do some precomputing to make this much faster: for each possible circle center \((x, y)\), the only radius \(R\) we would ever want to use is the smallest one that contains all of the points. This gives us at most \(51^2 \approx 2{,}500\) possible circles to use, and sometimes fewer because \(R\) will be greater than \(50\) for some choices of \((x, y)\).
|
6 |
+
|
7 |
+
Now we can simply compute the area of the intersection of each of these \(2{,}500^2 \approx 6{,}000{,}000\) pairs, and select the pair with the smallest intersection. If we encounter a tie, we break it arbitrarily.
|
8 |
+
|
9 |
+
Once we've decided which pair of circles to use, we need to decide which one is \(A\) and which one is \(B\). While the function for generating tree locations may look like it spreads trees evenly across a given circle, it's actually biased towards placing trees towards the center of \(A\). The function generates \(r\) uniformly from \([0, R)\), which means (for example) that half of the points will land within a radius of \(R/2\) which is only a quarter of the area of the whole circle. If we compute the sum of distances from each point to the centers of the two circles, the circle with the lower sum is more likely to be \(A\).
|
10 |
+
|
11 |
+
Empirically, this approach correctly predicts approximately \(90\%\) of the cases when \(500\) points are sampled.
|
2022/finals/tile_transposing.cpp
ADDED
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#include <algorithm>
|
2 |
+
#include <cstring>
|
3 |
+
#include <iostream>
|
4 |
+
#include <stack>
|
5 |
+
#include <tuple>
|
6 |
+
#include <unordered_set>
|
7 |
+
#include <vector>
|
8 |
+
using namespace std;
|
9 |
+
|
10 |
+
const int LIM = 3005;
|
11 |
+
const int MAXN = LIM * LIM;
|
12 |
+
|
13 |
+
vector<int> adj[MAXN];
|
14 |
+
unordered_set<int> cutpoints;
|
15 |
+
vector<int> comp;
|
16 |
+
vector<vector<int>> bcc, bcc_adj;
|
17 |
+
|
18 |
+
void reset_edges() {
|
19 |
+
for (int i = 0; i < MAXN; i++) {
|
20 |
+
adj[i].clear();
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
void add_edge(int u, int v) {
|
25 |
+
adj[u].push_back(v);
|
26 |
+
adj[v].push_back(u);
|
27 |
+
}
|
28 |
+
|
29 |
+
void tarjan(int N) {
|
30 |
+
cutpoints.clear();
|
31 |
+
bcc.clear();
|
32 |
+
comp.assign(N, -1);
|
33 |
+
vector<int> vis(N), parent(N, -1), children(N), tin(N), pushed(N), low(N);
|
34 |
+
vector<bool> is_cut(N);
|
35 |
+
int curr_root = 0;
|
36 |
+
stack<tuple<int, int, int>> dfs;
|
37 |
+
stack<int> st;
|
38 |
+
for (int i = 0; i < N; i++) {
|
39 |
+
if (vis[i]) {
|
40 |
+
continue;
|
41 |
+
}
|
42 |
+
vis[i] = ++curr_root;
|
43 |
+
tin[i] = 0;
|
44 |
+
int timer = 1;
|
45 |
+
dfs.push({i, 0, 0});
|
46 |
+
while (!dfs.empty()) {
|
47 |
+
auto [u, j, t] = dfs.top();
|
48 |
+
low[u] = t;
|
49 |
+
if (!pushed[u]) {
|
50 |
+
st.push(u);
|
51 |
+
pushed[u] = 1;
|
52 |
+
}
|
53 |
+
if (j == (int)adj[u].size()) {
|
54 |
+
if ((parent[u] == -1 && children[u] >= 2) ||
|
55 |
+
(parent[u] != -1 && is_cut[u])) {
|
56 |
+
cutpoints.insert(u);
|
57 |
+
}
|
58 |
+
if (t >= tin[u]) {
|
59 |
+
vector<int> component;
|
60 |
+
do {
|
61 |
+
int v = st.top();
|
62 |
+
component.push_back(v);
|
63 |
+
comp[v] = bcc.size();
|
64 |
+
st.pop();
|
65 |
+
} while (comp[u] == -1);
|
66 |
+
bcc.push_back(component);
|
67 |
+
}
|
68 |
+
dfs.pop();
|
69 |
+
continue;
|
70 |
+
}
|
71 |
+
int v = adj[u][j];
|
72 |
+
if (parent[u] == v) {
|
73 |
+
get<1>(dfs.top())++;
|
74 |
+
continue;
|
75 |
+
}
|
76 |
+
if (vis[v] == 0) {
|
77 |
+
vis[v] = curr_root;
|
78 |
+
parent[v] = u;
|
79 |
+
children[u]++;
|
80 |
+
dfs.push({v, 0, timer});
|
81 |
+
tin[v] = timer++;
|
82 |
+
continue;
|
83 |
+
}
|
84 |
+
is_cut[u] = is_cut[u] || low[v] >= tin[u];
|
85 |
+
if (vis[v] == curr_root && comp[v] == -1 && low[v] < t) {
|
86 |
+
get<2>(dfs.top()) = low[v];
|
87 |
+
}
|
88 |
+
get<1>(dfs.top())++;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
bcc_adj.assign(bcc.size(), {});
|
92 |
+
for (int i = 0; i < N; i++) {
|
93 |
+
for (int j = 0; j < (int)adj[i].size(); j++) {
|
94 |
+
if (comp[i] != comp[adj[i][j]]) {
|
95 |
+
bcc_adj[comp[i]].push_back(comp[adj[i][j]]);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
template <class Value>
|
102 |
+
class LinkCut {
|
103 |
+
struct Node {
|
104 |
+
int ch[2] = {0, 0}, p = 0;
|
105 |
+
Value self = 0, path = 0; // Path aggregates
|
106 |
+
Value sub = 0, vir = 0; // Subtree aggregates
|
107 |
+
bool flip = 0; // Lazy tags
|
108 |
+
};
|
109 |
+
|
110 |
+
vector<Node> T;
|
111 |
+
|
112 |
+
void push(int x) {
|
113 |
+
if (x == 0 || !T[x].flip) {
|
114 |
+
return;
|
115 |
+
}
|
116 |
+
int l = T[x].ch[0], r = T[x].ch[1];
|
117 |
+
T[l].flip ^= 1;
|
118 |
+
T[r].flip ^= 1;
|
119 |
+
swap(T[x].ch[0], T[x].ch[1]);
|
120 |
+
T[x].flip = 0;
|
121 |
+
}
|
122 |
+
|
123 |
+
void pull(int x) {
|
124 |
+
int l = T[x].ch[0], r = T[x].ch[1];
|
125 |
+
push(l);
|
126 |
+
push(r);
|
127 |
+
T[x].path = T[l].path + T[x].self + T[r].path;
|
128 |
+
T[x].sub = T[x].vir + T[l].sub + T[r].sub + T[x].self;
|
129 |
+
}
|
130 |
+
|
131 |
+
void set(int x, int d, int y) {
|
132 |
+
T[x].ch[d] = y;
|
133 |
+
T[y].p = x;
|
134 |
+
pull(x);
|
135 |
+
}
|
136 |
+
|
137 |
+
void splay(int x) {
|
138 |
+
auto dir = [&](int x) {
|
139 |
+
int p = T[x].p;
|
140 |
+
if (p == 0) {
|
141 |
+
return -1;
|
142 |
+
}
|
143 |
+
return T[p].ch[0] == x ? 0 : T[p].ch[1] == x ? 1 : -1;
|
144 |
+
};
|
145 |
+
auto rotate = [&](int x) {
|
146 |
+
int y = T[x].p, z = T[y].p, dx = dir(x), dy = dir(y);
|
147 |
+
set(y, dx, T[x].ch[!dx]);
|
148 |
+
set(x, !dx, y);
|
149 |
+
if (~dy) {
|
150 |
+
set(z, dy, x);
|
151 |
+
}
|
152 |
+
T[x].p = z;
|
153 |
+
};
|
154 |
+
for (push(x); ~dir(x);) {
|
155 |
+
int y = T[x].p, z = T[y].p;
|
156 |
+
push(z);
|
157 |
+
push(y);
|
158 |
+
push(x);
|
159 |
+
int dx = dir(x), dy = dir(y);
|
160 |
+
if (~dy) {
|
161 |
+
rotate(dx != dy ? x : y);
|
162 |
+
}
|
163 |
+
rotate(x);
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
int access(int x) {
|
168 |
+
int v = 0;
|
169 |
+
for (int u = x; u != 0; u = T[u].p) {
|
170 |
+
splay(u);
|
171 |
+
int &ov = T[u].ch[1];
|
172 |
+
T[u].vir += T[ov].sub;
|
173 |
+
T[u].vir -= T[v].sub;
|
174 |
+
ov = v;
|
175 |
+
pull(u);
|
176 |
+
v = u;
|
177 |
+
}
|
178 |
+
splay(x);
|
179 |
+
return v;
|
180 |
+
}
|
181 |
+
|
182 |
+
void reroot(int x) {
|
183 |
+
access(x);
|
184 |
+
T[x].flip ^= 1;
|
185 |
+
push(x);
|
186 |
+
}
|
187 |
+
|
188 |
+
public:
|
189 |
+
LinkCut(int n = 0) : T(n + 1) {}
|
190 |
+
|
191 |
+
void Init(int u, Value v) {
|
192 |
+
T[++u].self = v;
|
193 |
+
pull(u);
|
194 |
+
}
|
195 |
+
|
196 |
+
void Reset(int n) {
|
197 |
+
T.clear();
|
198 |
+
T.resize(n + 1);
|
199 |
+
}
|
200 |
+
|
201 |
+
void Link(int u, int v) {
|
202 |
+
if (u == v || LCA(u, v) != -1) {
|
203 |
+
return;
|
204 |
+
}
|
205 |
+
reroot(++u);
|
206 |
+
access(++v);
|
207 |
+
T[v].vir += T[u].sub;
|
208 |
+
T[u].p = v;
|
209 |
+
pull(v);
|
210 |
+
}
|
211 |
+
|
212 |
+
void Cut(int u, int v) {
|
213 |
+
if (u == v || LCA(u, v) == -1) {
|
214 |
+
return;
|
215 |
+
}
|
216 |
+
reroot(++u);
|
217 |
+
access(++v);
|
218 |
+
T[v].ch[0] = T[u].p = 0;
|
219 |
+
pull(v);
|
220 |
+
}
|
221 |
+
|
222 |
+
// Rooted tree LCA. Returns -1 if u and v aren't connected.
|
223 |
+
int LCA(int u, int v) {
|
224 |
+
if (++u == ++v) {
|
225 |
+
return u;
|
226 |
+
}
|
227 |
+
access(u);
|
228 |
+
int ret = access(v);
|
229 |
+
return T[u].p ? ret : -1;
|
230 |
+
}
|
231 |
+
|
232 |
+
// Query subtree of u where v is outside the subtree.
|
233 |
+
// Pass u = v to get the aggregate for the entire tree containing u.
|
234 |
+
Value Subtree(int u, int v) {
|
235 |
+
reroot(++v);
|
236 |
+
access(++u);
|
237 |
+
return T[u].vir + T[u].self;
|
238 |
+
}
|
239 |
+
|
240 |
+
Value Path(int u, int v) {
|
241 |
+
reroot(++u);
|
242 |
+
access(++v);
|
243 |
+
return T[v].path;
|
244 |
+
}
|
245 |
+
|
246 |
+
void Update(int u, Value v) {
|
247 |
+
access(++u);
|
248 |
+
T[u].self = v;
|
249 |
+
pull(u);
|
250 |
+
}
|
251 |
+
};
|
252 |
+
|
253 |
+
// Main algorithm.
|
254 |
+
|
255 |
+
int R, C;
|
256 |
+
int G[LIM][LIM];
|
257 |
+
LinkCut<int> lcf;
|
258 |
+
|
259 |
+
inline int getn(int r, int c) { return r * C + c; }
|
260 |
+
inline int getr(int n) { return n / C; }
|
261 |
+
inline int getc(int n) { return n % C; }
|
262 |
+
|
263 |
+
// Size of group connected to (r2, c2) after swapping (r1, c1) to (r2, c2).
|
264 |
+
int num_cleared(int r1, int c1, int r2, int c2) {
|
265 |
+
int res = 0;
|
266 |
+
int u = getn(r1, c1), cu = comp[u];
|
267 |
+
// If u is a cutpoint, disconnect it from all neighboring BCCs.
|
268 |
+
if (cutpoints.count(u)) {
|
269 |
+
for (int v : adj[u]) {
|
270 |
+
int cv = comp[v];
|
271 |
+
if (cu != cv) {
|
272 |
+
lcf.Cut(cu, cv);
|
273 |
+
}
|
274 |
+
}
|
275 |
+
}
|
276 |
+
// Get a representative for each neighboring group of (r2, c2).
|
277 |
+
unordered_set<int> seen_groups;
|
278 |
+
bool seen_orig = false; // Whether we've seen the original group of cu.
|
279 |
+
for (auto [dr, dc] : {pair{-1, 0}, {0, 1}, {1, 0}, {0, -1}}) {
|
280 |
+
int r3 = r2 + dr, c3 = c2 + dc;
|
281 |
+
if (r3 < 0 || r3 >= R || c3 < 0 || c3 >= C) {
|
282 |
+
continue;
|
283 |
+
}
|
284 |
+
if (!(r1 == r3 && c1 == c3) && G[r1][c1] == G[r3][c3]) {
|
285 |
+
int cv = comp[getn(r3, c3)];
|
286 |
+
bool seen = false; // Have we seen the same group?
|
287 |
+
for (int cmp : seen_groups) {
|
288 |
+
if (lcf.LCA(cv, cmp) != -1) {
|
289 |
+
seen = true;
|
290 |
+
break;
|
291 |
+
}
|
292 |
+
}
|
293 |
+
if (!seen) {
|
294 |
+
if (lcf.LCA(cu, cv) != -1) {
|
295 |
+
seen_orig = true;
|
296 |
+
}
|
297 |
+
res += lcf.Subtree(cv, cv);
|
298 |
+
seen_groups.insert(cv);
|
299 |
+
}
|
300 |
+
}
|
301 |
+
}
|
302 |
+
// If we didn't encounter the original component, add 1 for the cell itself.
|
303 |
+
if (!seen_orig) {
|
304 |
+
res++;
|
305 |
+
}
|
306 |
+
// Undo disconnections.
|
307 |
+
if (cutpoints.count(u)) {
|
308 |
+
for (int v : adj[u]) {
|
309 |
+
int cv = comp[v];
|
310 |
+
if (cu != cv) {
|
311 |
+
lcf.Link(cu, cv);
|
312 |
+
}
|
313 |
+
}
|
314 |
+
}
|
315 |
+
return res >= 3 ? res : 0;
|
316 |
+
}
|
317 |
+
|
318 |
+
long long solve() {
|
319 |
+
reset_edges();
|
320 |
+
// Build graph.
|
321 |
+
for (int r = 0; r < R; r++) {
|
322 |
+
for (int c = 0; c < C; c++) {
|
323 |
+
for (auto [dr, dc] : {pair{0, 1}, {1, 0}}) {
|
324 |
+
int r2 = r + dr, c2 = c + dc;
|
325 |
+
if (r2 < 0 || r2 >= R || c2 < 0 || c2 >= C) {
|
326 |
+
continue;
|
327 |
+
}
|
328 |
+
if (G[r][c] == G[r2][c2]) {
|
329 |
+
add_edge(getn(r, c), getn(r2, c2));
|
330 |
+
}
|
331 |
+
}
|
332 |
+
}
|
333 |
+
}
|
334 |
+
// Compute BCC and block forest.
|
335 |
+
tarjan(R * C);
|
336 |
+
int bcc_nodes = (int)bcc.size();
|
337 |
+
// Create link-cut forest from BCC.
|
338 |
+
lcf.Reset(bcc_nodes);
|
339 |
+
for (int i = 0; i < bcc_nodes; i++) {
|
340 |
+
lcf.Init(i, bcc[i].size());
|
341 |
+
}
|
342 |
+
for (int i = 0; i < bcc_nodes; i++) {
|
343 |
+
for (int j : bcc_adj[i]) {
|
344 |
+
lcf.Link(i, j);
|
345 |
+
}
|
346 |
+
}
|
347 |
+
// Try swapping each neighbor.
|
348 |
+
long long ans = 0;
|
349 |
+
for (int r = 0; r < R; r++) {
|
350 |
+
for (int c = 0; c < C; c++) {
|
351 |
+
// Only check right and bottom for ordered pairs.
|
352 |
+
for (auto [dr, dc] : {pair{0, 1}, {1, 0}}) {
|
353 |
+
int r2 = r + dr, c2 = c + dc;
|
354 |
+
if (r2 < 0 || r2 >= R || c2 < 0 || c2 >= C) {
|
355 |
+
continue;
|
356 |
+
}
|
357 |
+
if (G[r][c] != G[r2][c2]) {
|
358 |
+
ans += num_cleared(r, c, r2, c2) + num_cleared(r2, c2, r, c);
|
359 |
+
}
|
360 |
+
}
|
361 |
+
}
|
362 |
+
}
|
363 |
+
return 2 * ans;
|
364 |
+
}
|
365 |
+
|
366 |
+
int main() {
|
367 |
+
ios_base::sync_with_stdio(false);
|
368 |
+
cin.tie(nullptr);
|
369 |
+
int T;
|
370 |
+
cin >> T;
|
371 |
+
for (int t = 1; t <= T; t++) {
|
372 |
+
memset(G, 0, sizeof G);
|
373 |
+
cin >> R >> C;
|
374 |
+
for (int r = 0; r < R; r++) {
|
375 |
+
for (int c = 0; c < C; c++) {
|
376 |
+
cin >> G[r][c];
|
377 |
+
}
|
378 |
+
}
|
379 |
+
cout << "Case #" << t << ": " << solve() << endl;
|
380 |
+
}
|
381 |
+
return 0;
|
382 |
+
}
|
2022/finals/tile_transposing.in
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c7988564fd6a6e8beb23b0e2ff6d4cd092af9fe9784bb761f207b128ae3a86b7
|
3 |
+
size 60218996
|
2022/finals/tile_transposing.md
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*Bejeweled*™ is a classic puzzle game where the player tries to match three-in-a-row in a 2D grid of tiles by swapping pairs of adjacent tiles.
|
2 |
+
|
3 |
+
*Isblinged*™ is Hacker Cup's spinoff, played on a grid of \(R\) rows by \(C\) columns of tiles. The tile at \((i, j)\) is of an integer type \(G_{i,j}\). A *group* refers to three or more tiles of the same type, connected directly or indirectly via the four orthogonal directions (left, right, up, and down). Initially, the given grid \(G\) may already contain groups.
|
4 |
+
|
5 |
+
The player may swap two orthogonally adjacent tiles *of different types*. If the swap results in either tile being in a group of three or more tiles, then all tiles in the *newly-formed group(s)* are cleared.
|
6 |
+
|
7 |
+
For the example below (sample case 2), swapping the first two tiles in row \(1\) would clear \(9\) tiles:
|
8 |
+
|
9 |
+
{{PHOTO_ID:1310493279783732|WIDTH:700}}
|
10 |
+
|
11 |
+
On the other hand, swapping the first two tiles in the second column would clear \(12\) tiles;
|
12 |
+
|
13 |
+
{{PHOTO_ID:650302073463012|WIDTH:700}}
|
14 |
+
|
15 |
+
Note that the type-3 group is not cleared because it doesn't contain a swapped tile.
|
16 |
+
|
17 |
+
Please find the *sum* of tiles that would be cleared over all possible theoretical swaps of ordered pairs of tiles \(G_{i_1, j_1}\) and \(G_{i_2, j_2}\) such that \(|i_1 - i_2| + |j_1 - j_2| = 1\) and \(G_{i_1, j_1} \ne G_{i_2, j_2}\).
|
18 |
+
|
19 |
+
|
20 |
+
# Constraints
|
21 |
+
|
22 |
+
\(1 \le T \le 105\)
|
23 |
+
\(1 \le R, C \le 3000\)
|
24 |
+
\(1 \le G_{i,j} \le 10^9\)
|
25 |
+
|
26 |
+
The sum of \(R*C\) across all test cases is at most \(40{,}000{,}000\).
|
27 |
+
|
28 |
+
|
29 |
+
# Input Format
|
30 |
+
|
31 |
+
Input begins with an integer \(T\), the number of cases. For each case, there is first a line containing two space-separated integers, \(R\) and \(C\). Then, \(R\) lines follow, the \(i\)th of which contains \(C\) space-separated integers \(G_{i,1..C}\).
|
32 |
+
|
33 |
+
|
34 |
+
# Output Format
|
35 |
+
|
36 |
+
For the \(i\)th case, print a line containing `"Case #i: "` followed by a single integer, the sum of tiles that can be cleared with a single swap.
|
37 |
+
|
38 |
+
|
39 |
+
# Sample Explanation
|
40 |
+
|
41 |
+
In the first sample case:
|
42 |
+
- \(G_{1,1}\), \(G_{1,3}\), and \(G_{2,3}\) can't be swapped with anything that leads to any tiles being cleared.
|
43 |
+
- \(G_{1,2}\) can be swapped with the type-2 tile below to clear \(3\) tiles.
|
44 |
+
- \(G_{2,1}\) can be swapped with the type-2 tile right of it to clear \(3\) tiles.
|
45 |
+
- \(G_{2,2}\) can be swapped with either the type-1 cell above or to the left, each clearing \(3\) tiles.
|
46 |
+
|
47 |
+
The answer is therefore \(3 + 3 + 2*3 = 12\).
|
48 |
+
|
49 |
+
In the second sample case, the unordered pairs of swaps clearing non-zero numbers of tiles are:
|
50 |
+
- \(G_{1,1} \leftrightarrow G_{1,2} \): clearing \(9\) tiles
|
51 |
+
- \(G_{1,2} \leftrightarrow G_{1,3} \): clearing \(5 + 3 = 8\) tiles
|
52 |
+
- \(G_{1,2} \leftrightarrow G_{2,1} \): clearing \(9 + 3 = 12\) tiles
|
53 |
+
- \(G_{1,3} \leftrightarrow G_{2,3} \): clearing \(5\) tiles
|
54 |
+
- \(G_{1,4} \leftrightarrow G_{2,4} \): clearing \(4\) tiles
|
55 |
+
- \(G_{2,2} \leftrightarrow G_{2,3} \): clearing \(6\) tiles
|
56 |
+
- \(G_{2,2} \leftrightarrow G_{3,2} \): clearing \(4\) tiles
|
57 |
+
- \(G_{2,4} \leftrightarrow G_{2,5} \): clearing \(4\) tiles
|
58 |
+
- \(G_{3,1} \leftrightarrow G_{3,2} \): clearing \(4\) tiles
|
59 |
+
|
60 |
+
Doubling the sum for ordered pairs, we get \(2*(9+8+12+5+4+6+4+4+4) = 112\).
|
61 |
+
|
2022/finals/tile_transposing.out
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Case #1: 0
|
2 |
+
Case #2: 0
|
3 |
+
Case #3: 1982
|
4 |
+
Case #4: 130
|
5 |
+
Case #5: 0
|
6 |
+
Case #6: 12
|
7 |
+
Case #7: 0
|
8 |
+
Case #8: 0
|
9 |
+
Case #9: 0
|
10 |
+
Case #10: 30
|
11 |
+
Case #11: 32
|
12 |
+
Case #12: 0
|
13 |
+
Case #13: 0
|
14 |
+
Case #14: 23978
|
15 |
+
Case #15: 12582
|
16 |
+
Case #16: 7930
|
17 |
+
Case #17: 0
|
18 |
+
Case #18: 14
|
19 |
+
Case #19: 32
|
20 |
+
Case #20: 18
|
21 |
+
Case #21: 0
|
22 |
+
Case #22: 76
|
23 |
+
Case #23: 40
|
24 |
+
Case #24: 56
|
25 |
+
Case #25: 0
|
26 |
+
Case #26: 68998
|
27 |
+
Case #27: 31032
|
28 |
+
Case #28: 18916
|
29 |
+
Case #29: 0
|
30 |
+
Case #30: 23540
|
31 |
+
Case #31: 12614
|
32 |
+
Case #32: 8064
|
33 |
+
Case #33: 0
|
34 |
+
Case #34: 68582
|
35 |
+
Case #35: 31554
|
36 |
+
Case #36: 18714
|
37 |
+
Case #37: 0
|
38 |
+
Case #38: 200884422
|
39 |
+
Case #39: 24890006
|
40 |
+
Case #40: 12909246
|
41 |
+
Case #41: 0
|
42 |
+
Case #42: 692
|
43 |
+
Case #43: 544
|
44 |
+
Case #44: 8326
|
45 |
+
Case #45: 7928
|
46 |
+
Case #46: 15872
|
47 |
+
Case #47: 8434
|
48 |
+
Case #48: 9084
|
49 |
+
Case #49: 8452
|
50 |
+
Case #50: 122802030
|
51 |
+
Case #51: 15902868
|
52 |
+
Case #52: 8255980
|
53 |
+
Case #53: 5367684
|
54 |
+
Case #54: 1515414
|
55 |
+
Case #55: 417052
|
56 |
+
Case #56: 537018
|
57 |
+
Case #57: 169112
|
58 |
+
Case #58: 24009981167522
|
59 |
+
Case #59: 15986473629556
|
60 |
+
Case #60: 23754469857978
|
61 |
+
Case #61: 1602978
|
62 |
+
Case #62: 23322
|
63 |
+
Case #63: 22302
|
64 |
+
Case #64: 1841520
|
65 |
+
Case #65: 1945100
|
66 |
+
Case #66: 239564
|
67 |
+
Case #67: 1546622
|
68 |
+
Case #68: 0
|
69 |
+
Case #69: 23366
|
70 |
+
Case #70: 0
|
71 |
+
Case #71: 1556198
|
72 |
+
Case #72: 0
|
73 |
+
Case #73: 237642
|
74 |
+
Case #74: 1831920
|
75 |
+
Case #75: 250776
|
76 |
+
Case #76: 242612
|
77 |
+
Case #77: 244878
|
78 |
+
Case #78: 23968
|
79 |
+
Case #79: 1932464
|
80 |
+
Case #80: 0
|
81 |
+
Case #81: 23734
|
82 |
+
Case #82: 0
|
83 |
+
Case #83: 23536
|
84 |
+
Case #84: 244228
|
85 |
+
Case #85: 0
|
86 |
+
Case #86: 23056
|
87 |
+
Case #87: 0
|
88 |
+
Case #88: 0
|
89 |
+
Case #89: 234016
|
90 |
+
Case #90: 23220
|
91 |
+
Case #91: 240212
|
92 |
+
Case #92: 233526
|
93 |
+
Case #93: 240062
|
94 |
+
Case #94: 23662
|
95 |
+
Case #95: 1866038
|
96 |
+
Case #96: 1630710
|
97 |
+
Case #97: 231290
|
98 |
+
Case #98: 232490
|
99 |
+
Case #99: 238914
|
100 |
+
Case #100: 235878
|
101 |
+
Case #101: 1566530
|
102 |
+
Case #102: 0
|
103 |
+
Case #103: 23222
|
104 |
+
Case #104: 0
|
105 |
+
Case #105: 235902
|
2022/finals/tile_transposing_sol.md
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Instead of swapping, first imagine shifting a tile \(G_{i,j}\) to replace an adjacent cell at \((i', j')\), leaving behind an empty space (instead of a different tile). Many things can happen:
|
2 |
+
- The tile itself can be disconnected from its old group.
|
3 |
+
- The tile can become connected to a new group.
|
4 |
+
- The tile, moving away, can break up its old group into multiple parts.
|
5 |
+
- The tile, at its new location, can merge different pre-existing groups into one.
|
6 |
+
|
7 |
+
Let \(C(i, j, i', j')\) denote the number of type-\(G_{i, j}\) tiles that will be connected to \((i', j')\) after shifting \(G_{i, j}\) to \((i', j')\). We can individually compute \(C(i, j, i', j') + C(i', j', i, j)\) to get the total number of tiles cleared in a single swap \(G_{i, j} \leftrightarrow G_{i',j'}\). The challenge is doing so efficiently.
|
8 |
+
|
9 |
+
We can build a graph with a node for each tile and an edge for every pair of adjacent tiles of the same type. There will be \(V = R*C \le 9{,}000{,}000\) nodes and \(E = O(4*R*C)\) edges. We could then theoretically solve the [dynamic connectivity](https://en.wikipedia.org/wiki/Dynamic_connectivity) problem to simulate adding/removing edges for each swap, and querying connected component sizes. Actually, we would only need to delete edges (decremental connectivity), query all neighbors of the new cell, and roll back the deletion using a persistent data structure. Unfortunately, even decremental connectivity is difficult to perform efficiently on general graphs.
|
10 |
+
|
11 |
+
Instead, we can try taking advantage of the structure of the graph. If we decompose the graph into [biconnected components](https://en.wikipedia.org/wiki/Biconnected_component) (BCCs), we see that the entire graph is a forest of block-cut trees (one for each tile group) connected by bridges at cut vertices (articulation points). For example, the cut vertices of the second sample case is denoted by asterisks:
|
12 |
+
|
13 |
+
```
|
14 |
+
1 2 1 1* 1*
|
15 |
+
1* 1 2 2 1*
|
16 |
+
1 3 3* 3 1
|
17 |
+
```
|
18 |
+
|
19 |
+
When we shift \(G_{i, j}\) to a neighboring cell \((i', j')\), there are two cases:
|
20 |
+
|
21 |
+
_Case 1_: Tile \(G_{i, j}\) was not a cut vertex: All tiles of the original group will remain connected, except maybe the shifted tile itself. Then, \(C(i, j, i', j')\) can be computed by summing the sizes of groups of type \(G_{i,j}\) that are connected to \((i', j')\). Note that neighbors can be in the same group as each other, or in \(G_{i, j}\)'s original group. We'll need a way to check the connectness of two arbitrary nodes to avoid double counting.
|
22 |
+
|
23 |
+
_Case 2_: Tile \(G_{i, j}\) was a cut vertex: We'll need a way to temporarily disconnect it before calculating the group sizes connected to \((i', j')\). The number of edges for the cut vertex (a.k.a. its color) can only be \(2\) or \(3\), for if all \(4\) neighbors were filled, the swap wouldn't be possible.
|
24 |
+
|
25 |
+
\(2\)-colored cut vertex examples:
|
26 |
+
```
|
27 |
+
1 1* 1 1 1*
|
28 |
+
1* 1
|
29 |
+
```
|
30 |
+
\(3\)-colored cut vertex example:
|
31 |
+
```
|
32 |
+
1 1
|
33 |
+
1 1*
|
34 |
+
1 1
|
35 |
+
```
|
36 |
+
|
37 |
+
In the above cases, each cut vertex is always in its own BCC block, so disconnecting the node is the same as disconnecting the entire block in the block forest.
|
38 |
+
|
39 |
+
Working through examples by hand, we see that the only way for a cut vertex to *not* be in its own size-\(1\) block is as follows (left). We have a \(2\)-colored cut vertex but its block is the entire loop:
|
40 |
+
```
|
41 |
+
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
42 |
+
1 1 1 1 1 1 1
|
43 |
+
1 1* ... 1 --> 1 1 1 1 or 1 1 1 1
|
44 |
+
1 1 1 1 1 1
|
45 |
+
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
46 |
+
```
|
47 |
+
|
48 |
+
In this case, the shifted tile may become connected to a different group (middle), or to its own group again (right). Here, we can skip the disconnection/rolling back and just get the total group sizes of the other \(3\) neighbors of \((i', j')\). We'll only add \(1\) if the tile did not get reconnected to its original group.
|
49 |
+
|
50 |
+
With these observations, we can obtain the answer by solving dynamic connectivity on the block forest. For each condensed block node, we'll store the number of actual nodes in the block, a.k.a. the block size. We'll need to efficiently:
|
51 |
+
|
52 |
+
- delete an edge (and undo the deletion)
|
53 |
+
- check connectivity
|
54 |
+
- query an aggregate function (here, the sum of BCC block sizes) for an entire block tree
|
55 |
+
|
56 |
+
One way is with a link-cut forest modified to handle [subtree aggregates](https://usaco.guide/adv/link-cut-tree?lang=cpp#link-cut-tree---subtrees) (full tree queries are just a special case), which can be done with [virtual subtrees](https://codeforces.com/blog/entry/67637#comment-650436). This was the intended solution, and directly supports all of the operations we need. Other approaches include persistent disjoint set union, DFS, and bookkeeping of node component sizes.
|
57 |
+
|
58 |
+
Biconnected components and cut vertices can be computed in \(\mathcal{O}(V + E)\) time using Tarjan's algorithm. For each \(C(i, j, i', j')\) calculation, we'll do a constant number of cuts, connectivity checks, and queries on the link-cut forest, taking \(\mathcal{O}(\log V)\) time among them. The overall time complexity to compute the answer across all possible swaps is therefore \(\mathcal{O}(E + V \log V)\).
|
2022/quals/1183048075593188.jpg
ADDED
![]() |
Git LFS Details
|
2022/quals/1264108514364518.jpg
ADDED
![]() |
Git LFS Details
|
2022/quals/356437426702208.jpg
ADDED
![]() |
Git LFS Details
|
2022/quals/459254706243127.jpg
ADDED
![]() |
Git LFS Details
|
2022/quals/5118404751621442.jpg
ADDED
![]() |
Git LFS Details
|
2022/quals/545859687328272.jpg
ADDED
![]() |
Git LFS Details
|
2022/quals/569216148234749.jpg
ADDED
![]() |
Git LFS Details
|