diff --git a/caderno.pdf b/caderno.pdf index 9d215e2f2a2af3eaa1555fdd4d3ab4666fdcac70..fd8c3722363caf575817cd20de9fc44fbba2ee86 100644 Binary files a/caderno.pdf and b/caderno.pdf differ diff --git a/contests/SBC19/A.cpp b/contests/SBC19/A.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8be3f8609d795ddad748329878aa8ae48639cc8 --- /dev/null +++ b/contests/SBC19/A.cpp @@ -0,0 +1,87 @@ +#include <bits/stdc++.h> + +#define MAX 1010 +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +struct Circle { + int x, y, r; + Circle() {} + + bool inter(Circle c) { + return (c.x - x)*(c.x - x) + (c.y - y)*(c.y - y) <= (c.r + r)*(c.r + r); + } +}; + +#define R 1001 +#define L 1002 +#define U 1003 +#define D 1004 + +int par[MAX]; +int rnk[MAX]; + +int find_set(int x) { + if (par[x] != x) + par[x] = find_set(par[x]); + return par[x]; +} + +void union_set(int a, int b) { + a = find_set(a); + b = find_set(b); + + if (a == b) return; + if (rnk[a] < rnk[b]) swap(a, b); + if (rnk[a] == rnk[b]) rnk[a]++; + par[b] = a; +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int m, n, k; cin >> m >> n >> k; + vector<Circle> v(k); + + for (auto &i : v) + cin >> i.x >> i.y >> i.r; + + iota(par, par + MAX, 0); + for (int i = 0; i < k; ++i) { + for (int j = 0; j < k; ++j) + if (v[i].inter(v[j])) + union_set(i, j); + + if (v[i].x + v[i].r >= m) union_set(R, i); + if (v[i].x - v[i].r <= 0) union_set(L, i); + if (v[i].y + v[i].r >= n) union_set(U, i); + if (v[i].y - v[i].r <= 0) union_set(D, i); + } + + if (find_set(R) == find_set(L) || + find_set(L) == find_set(D) || + find_set(U) == find_set(D) || + find_set(R) == find_set(U)) + cout << "N" << ende; + else + cout << "S" << ende; + + return 0; +} diff --git a/contests/SBC19/B.cpp b/contests/SBC19/B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db754cb414921a22e0370a292ce117a9f8f15344 --- /dev/null +++ b/contests/SBC19/B.cpp @@ -0,0 +1,32 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n; cin >> n; + vector<int> v(n); + for (auto &i : v) cin >> i; + + cout << ((*max_element(all(v)) == v[0]) ? "S" : "N") << ende; + return 0; +} diff --git a/contests/SBC19/D.cpp b/contests/SBC19/D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08b1b28966490feaa598f88f6edd947be8fddf18 --- /dev/null +++ b/contests/SBC19/D.cpp @@ -0,0 +1,70 @@ +#include <bits/stdc++.h> + +#define MAX 101010 +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +int par[MAX]; +int heavy[MAX]; +int sz[MAX]; +vector<int> graph[MAX]; + +int dfs(int x, int p = -1) { + par[x] = p; + + int max_size = 0; + for (auto i : graph[x]) + if (i != p) { + int isize = dfs(i, x); + if (isize > max_size) + max_size = isize, heavy[x] = i; + } + + return max_size + 1; +} + +void decompose(int x, int h = 0) { + sz[h]++; + + if (heavy[x] != -1) + decompose(heavy[x], h); + for (auto i : graph[x]) + if (i != par[x] && i != heavy[x]) + decompose(i, i); +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n, k; cin >> n >> k; + for (int i = 2; i <= n; ++i) { + int x; cin >> x; + graph[x-1].pb(i-1); + graph[i-1].pb(x-1); + } + + mset(heavy, -1); + dfs(0); + decompose(0); + + sort(sz, sz + MAX); + cout << accumulate(sz + MAX - k, sz + MAX, 0) << ende; + return 0; +} diff --git a/contests/SBC19/F.cpp b/contests/SBC19/F.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daea4fc898397648f27a7ad06b3a21ef0f447200 --- /dev/null +++ b/contests/SBC19/F.cpp @@ -0,0 +1,129 @@ +#include <bits/stdc++.h> + +#define MAX 101010 +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +#define left(x) (x << 1) +#define right(x) ((x << 1) + 1) + +int N = 100001; +int tree[MAX*4], cnt[MAX*4]; + +struct LazySegmentTree { + void init() { + mset(tree, 0); + mset(cnt, 0); + } + + void update(int i, int j, int val, + int node = 1, int l = 0, int r = N - 1) { + if (l > r || l > j || r < i) return; + + if (i <= l && r <= j) + tree[node] += val; + else { + int m = (l + r) / 2; + update(i, j, val, left(node), l, m); + update(i, j, val, right(node), m + 1, r); + } + + if (tree[node]) + cnt[node] = r - l + 1; + else { + cnt[node] = 0; + if (l < r) cnt[node] = cnt[left(node)] + cnt[right(node)]; + } + } +}; + +struct Segment { + int x1, y1, x2, y2; + + Segment() {} + Segment(int x1, int y1, int x2, int y2) : + x1(x1), y1(y1), x2(x2), y2(y2) + {} +}; + +struct Event { + int x1, x2, y; + int beg; + + Event() {} + Event(int x1, int x2, int y, int b) : + x1(x1), x2(x2), y(y), beg(b) {} +}; + +Segment rect; +vector<Event> E; +vector<Segment> ss; +LazySegmentTree seg; + +double calc(int m) { + seg.init(); + int k = 0; + for (int i = 0; i < ss.size(); ++i) { + E[k++] = Event(ss[i].x1 - m, ss[i].x2 + m, ss[i].y1 - m, 1); + E[k++] = Event(ss[i].x1 - m, ss[i].x2 + m, ss[i].y2 + m, -1); + } + + sort(all(E), [&](const Event &a, const Event &b) { + return a.y < b.y; + }); + + k = 0; + ll ans = 0; + for (int i = rect.y1; i < rect.y2; ++i) { + for (; k < E.size() && E[k].y <= i; ++k) + if (E[k].x1 <= rect.x2 - 1 && E[k].x2 >= rect.x1) + seg.update(max(rect.x1, E[k].x1), min(rect.x2 - 1, E[k].x2 - 1), E[k].beg); + ans += (ll) cnt[1]; + } + + return ((ans*100) / ((ll) ((ll) rect.x2 - rect.x1) * ((ll) rect.y2 - rect.y1))); +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n; cin >> n; + E.resize(2*n); + ss.resize(n); + + for (auto &i : ss) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + i = Segment(min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2)); + } + + int p; cin >> p; + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + rect = Segment(min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2)); + + int l = 0, r = 101010; + for (int b = r / 2; b >= 1; b /= 2) + while (calc(l + b) < p) + l += b; + + cout << l + 1 << ende; + return 0; +} diff --git a/contests/SBC19/G.cpp b/contests/SBC19/G.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87d8d6f08e7358644afd0c8588b98e4d72ed6a9d --- /dev/null +++ b/contests/SBC19/G.cpp @@ -0,0 +1,123 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +struct MinCostMaxFlow { + struct Edge { + int u, v, cap; + double cost; + }; + + vector<Edge> edges; + vector<vector<int>> adj; + vector<int> vis, par, ind; + vector<double> dist; + + MinCostMaxFlow(int N) : + vis(N), dist(N), par(N), ind(N), adj(N) {} + + void add_edge(int u, int v, int cap, double cost) { + adj[u].pb(edges.size()); + edges.pb({ u, v, cap, cost }); + + adj[v].pb(edges.size()); + edges.pb({ v, u, 0, -cost }); + } + + bool spfa(int s, int t) { + fill(all(dist), inf); + dist[s] = 0; + + queue<int> Q; + Q.push(s); + + while (!Q.empty()) { + int u = Q.front(); Q.pop(); + vis[u] = 0; + + for (auto i : adj[u]) { + Edge &e = edges[i]; + int v = e.v; + + if (e.cap > 0 && dist[v] > dist[u] + e.cost) { + dist[v] = dist[u] + e.cost; + par[v] = u; + ind[v] = i; + + if (!vis[v]) { + Q.push(v); + vis[v] = 1; + } + } + } + } + + return dist[t] < inf; + } + + void run(int s, int t) { + double min_cost = 0; + int max_flow = 0; + + while (spfa(s, t)) { + int flow = inf; + for (int i = t; i != s; i = par[i]) + flow = min(flow, edges[ind[i]].cap); + + for (int i = t; i != s; i = par[i]) { + edges[ind[i] ].cap -= flow; + edges[ind[i]^1].cap += flow; + } + + min_cost += flow * dist[t]; + max_flow += flow; + } + } +}; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n; cin >> n; + + MinCostMaxFlow mcmf(2*n + 2); + for (int i = 0; i < n; ++i) { + mcmf.add_edge(0, i+1, 1, 0); + for (int j = 0; j < n; ++j) { + double x; cin >> x; + mcmf.add_edge(i+1, j+1+n, 1, -log(x)); + } + mcmf.add_edge(i+n+1,2*n+1, 1, 0); + } + + vector<int> ans(n); + mcmf.run(0, 2*n+1); + for (int i = 0; i < mcmf.edges.size(); ++i) + if (mcmf.edges[i].u > 0 && mcmf.edges[i].u <= n && + mcmf.edges[i].v >= n+1 && mcmf.edges[i].v < 2*n+1 && + mcmf.edges[i].cap == 0) + ans[mcmf.edges[i].v-(n+1)] = mcmf.edges[i].u; + + for (auto i : ans) + cout << i << " "; + cout << ende; + return 0; +} diff --git a/contests/SBC19/H.cpp b/contests/SBC19/H.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8cad16d1d590fa7e9972bbdd378065b1f721b509 --- /dev/null +++ b/contests/SBC19/H.cpp @@ -0,0 +1,33 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int v, n; cin >> v >> n; + for (int i = 1; i < 10; ++i) { + if (i > 1) cout << " "; + cout << ((v*n*i) - 1) / 10 + 1; + } + cout << ende; + return 0; +} diff --git a/contests/SBC19/I.cpp b/contests/SBC19/I.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44fcd8cf8dee158b2521d94670e30a6787761fe8 --- /dev/null +++ b/contests/SBC19/I.cpp @@ -0,0 +1,84 @@ +#include <bits/stdc++.h> + +#define MAX 410 +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +int graph[MAX][MAX]; +int dist[2][MAX][MAX][MAX]; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n, r; cin >> n >> r; + + vector<ii> t(n); + for (int i = 0; i < n; ++i) { + cin >> t[i].fi; + t[i].se = i; + } + + vector<ii> t0 = t; + vector<ii> t1 = t; + + sort(all(t0)); + sort(rall(t1)); + + for (int i = 0; i < r; ++i) { + int a, b, c; cin >> a >> b >> c; a--, b--; + graph[a][b] = c; + graph[b][a] = c; + } + + mset(dist, inf); + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) + if (i == j) + dist[0][0][i][j] = dist[1][0][i][j] = 0; + else if (graph[i][j]) + dist[0][0][i][j] = dist[1][0][i][j] = graph[i][j]; + + int kk0 = 1, kk1 = 1; + for (int k = 0; k < n; ++k) { + if (k && t0[k].fi != t0[k-1].fi) kk0++; + if (k && t1[k].fi != t1[k-1].fi) kk1++; + + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) { + dist[0][kk0][i][j] = min({dist[0][kk0-1][i][j], dist[0][kk0-1][i][t0[k].se] + dist[0][kk0-1][t0[k].se][j], + dist[0][kk0][i][j], dist[0][kk0][i][t0[k].se] + dist[0][kk0][t0[k].se][j]}); + dist[1][kk1][i][j] = min({dist[1][kk1-1][i][j], dist[1][kk1-1][i][t1[k].se] + dist[1][kk1-1][t1[k].se][j], + dist[1][kk1][i][j], dist[1][kk1][i][t1[k].se] + dist[1][kk1][t1[k].se][j]}); + } + } + + for (int k = kk0 + 1; k <= n; ++k) + memcpy(dist[0][k], dist[0][k-1], sizeof dist[0][k]); + for (int k = kk1 + 1; k <= n; ++k) + memcpy(dist[1][k], dist[1][k-1], sizeof dist[1][k]); + + int q; cin >> q; + while (q--) { + int a, b, k, t; cin >> a >> b >> k >> t; a--, b--; + cout << ((dist[t][k][a][b] == inf) ? -1 : dist[t][k][a][b]) << ende; + } + + return 0; +} diff --git a/contests/SBC19/J.cpp b/contests/SBC19/J.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec4c5b8e4656088abecb99054edc34fbbfe47637 --- /dev/null +++ b/contests/SBC19/J.cpp @@ -0,0 +1,71 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +int cnt[20][300]; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n, k; cin >> n >> k; k--; + vector<string> v(n); + for (int i = 0; i < n; ++i) { + cin >> v[i]; + for (auto j : v[i]) + cnt[i][j]++; + + if (cnt[i][v[i][0]] == 4 && i != k) + return cout << i + 1 << ende, 0; + } + + string ord = "A23456789DQJK"; + + cnt[k]['C']++; + int curr = k; + bool pode = false; + while (1) { + bool pass = false; + if (cnt[curr]['C'] && pode) { + cnt[curr]['C']--; + cnt[(curr+1)%n]['C']++; + pass = true; + pode = false; + } else if (!cnt[curr]['C'] || !pode) { + int mx = -1; + for (int i = 0; i < ord.size(); ++i) + if (cnt[curr][ord[i]] != 0 && (mx == -1 || cnt[curr][ord[i]] < cnt[curr][ord[mx]])) + mx = i; + + cnt[curr][ord[mx]]--; + cnt[(curr+1)%n][ord[mx]]++; + } + + if (!cnt[curr]['C']) + for (int i = 0; i < ord.size(); ++i) + if (cnt[curr][ord[i]] == 4) + return cout << curr + 1 << ende, 0; + + if (!pass) pode = true; + curr = (curr+1)%n; + } + + return 0; +} diff --git a/contests/SBC19/L.cpp b/contests/SBC19/L.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04ad5327ebe1b23bdecc67573f00de7a6c6f2037 --- /dev/null +++ b/contests/SBC19/L.cpp @@ -0,0 +1,30 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + ll n; cin >> n; + cout << (1LL << __builtin_popcountll(n)) << ende; + + return 0; +} diff --git a/contests/SBC19/M.cpp b/contests/SBC19/M.cpp new file mode 100644 index 0000000000000000000000000000000000000000..741935cbb1591c60285ca259c74410e9e2ebd825 --- /dev/null +++ b/contests/SBC19/M.cpp @@ -0,0 +1,50 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n, c, t; cin >> n >> c >> t; + vector<int> v(n); + for (auto &i : v) cin >> i; + + auto f = [&](int x) { + int memb = 0; + for (int i = 0, j = 0; i < n; i = j, ++memb) { + for (int sum = 0; j < n && (sum+v[j]-1)/t+1 <= x; ++j) + sum += v[j]; + if (i == j) + return false; + } + return (memb <= c); + }; + + int l = 1, r = (accumulate(all(v), 0) - 1) / t + 1; + for (int i = 0; i < 50; ++i) { + int m = (l + r) / 2; + if (!f(m)) l = m+1; + else r = m-1; + } + + cout << l << ende; + return 0; +} diff --git a/misc/environment/template.cpp b/misc/environment/template.cpp index 2f5418f9f3490d8a5947b9933c134c79cb1ee2e5..1cc4ff5334b6ffbd3dbb2f0b79d02af9d5d659b8 100644 --- a/misc/environment/template.cpp +++ b/misc/environment/template.cpp @@ -1,4 +1,5 @@ /// Template + #include <bits/stdc++.h> #define EPS 1e-6 diff --git a/notebook/gen_latex.py b/notebook/gen_latex.py index 3c57d3303a2ff7bf20e0ed905d5fcfbd6fe663d2..a8b4f3d6c04befb315d65ddc82d46904a2e67fb4 100644 --- a/notebook/gen_latex.py +++ b/notebook/gen_latex.py @@ -242,7 +242,6 @@ class LatexGenerator: def _gen_tree_latex(self, sub, path = '', depth = 0): if type(sub) == list: self._write('\\begin{multicols}{' + self._multicol(path) + '}\n') - print(path) for i in sub: source = self.SourceFile(path + i) self._gen_title_latex(source.name, depth) @@ -271,7 +270,8 @@ def get_args(): def main(): args = get_args() - tree = Tree(['algorithms', 'misc', 'problems', 'contests']) + #tree = Tree(['algorithms', 'misc', 'problems', 'contests']) + tree = Tree(['algorithms', 'misc']) tex = LatexGenerator(tree, args.output, args.header) if __name__ == "__main__":