Add a lot more problems and a TODO list

This commit is contained in:
2025-10-18 16:54:05 -03:00
parent f82c3630cf
commit f3275cd442
72 changed files with 9550 additions and 17 deletions

View File

@@ -0,0 +1,119 @@
/* Problem URL: https://codeforces.com/gym/104871/problem/B */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
using ld = long double;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string a;
cin >> a;
V<pair<ld, ld>> boys;
V<pair<ld, ld>> girls;
rep(i, n) {
ld x, y;
cin >> x >> y;
if (a[i] == 'B') {
boys.emplace_back(x, y);
} else {
girls.emplace_back(x, y);
}
}
auto dis = [&](pair<ld, ld> a, pair<ld, ld> b) {
ld x = a.first - b.first;
ld y = a.second - b.second;
return sqrt(x * x + y * y);
};
ld ans = 0;
rep(i, boys.size() >> 1) {
ans += dis(boys[i], boys[i + (boys.size() >> 1)]);
}
rep(i, girls.size() >> 1) {
ans += dis(girls[i], girls[i + (girls.size() >> 1)]);
}
cout << setprecision(12) << ans << '\n';
}

View File

@@ -0,0 +1,189 @@
/* Problem URL: https://codeforces.com/gym/104871/problem/C */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
#define int ll
#define INF (INT64_MAX >> 1)
struct dinitz {
const bool scaling = false; // com scaling -> O(nm log(MAXCAP)),
int lim; // com constante alta
struct edge {
int to, cap, rev, flow;
bool res;
edge(int to_, int cap_, int rev_, bool res_)
: to(to_), cap(cap_), rev(rev_), flow(0), res(res_) {}
};
vector<vector<edge>> g;
vector<int> lev, beg;
ll F;
dinitz(int n) : g(n), F(0) {}
void add(int a, int b, int c) {
g[a].emplace_back(b, c, g[b].size(), false);
g[b].emplace_back(a, 0, g[a].size()-1, true);
}
bool bfs(int s, int t) {
lev = vector<int>(g.size(), -1); lev[s] = 0;
beg = vector<int>(g.size(), 0);
queue<int> q; q.push(s);
while (q.size()) {
int u = q.front(); q.pop();
for (auto& i : g[u]) {
if (lev[i.to] != -1 or (i.flow == i.cap)) continue;
if (scaling and i.cap - i.flow < lim) continue;
lev[i.to] = lev[u] + 1;
q.push(i.to);
}
}
return lev[t] != -1;
}
int dfs(int v, int s, int f = INF) {
if (!f or v == s) return f;
for (int& i = beg[v]; i < g[v].size(); i++) {
auto& e = g[v][i];
if (lev[e.to] != lev[v] + 1) continue;
int foi = dfs(e.to, s, min(f, e.cap - e.flow));
if (!foi) continue;
e.flow += foi, g[e.to][e.rev].flow -= foi;
return foi;
}
return 0;
}
ll max_flow(int s, int t) {
for (lim = scaling ? (1<<30) : 1; lim; lim /= 2)
while (bfs(s, t)) while (int ff = dfs(s, t)) F += ff;
return F;
}
};
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int g, c, t;
cin >> g >> c >> t;
int size = g + c + t + 2;
dinitz din(size);
int s = g + c + t;
int si = g + c + t + 1;
ll total = 0;
rep(i, c) {
ll c;
cin >> c;
din.add(s, i, c);
total += c;
}
vl ccost(g);
rep(i, g) {
cin >> ccost[i];
din.add(i + c, si, INF);
}
rep(i, t) {
ll cost;
cin >> cost;
din.add(i + g + c, si, cost);
}
rep(i, c) {
rep(j, g) {
ll act;
cin >> act;
din.add(i, j + c, ccost[j] * act);
}
}
rep(i, c) {
int n;
cin >> n;
while (n--) {
int j;
cin >> j;
j--;
din.add(i, j + g + c, INF);
}
}
cout << total - din.max_flow(s, si) << '\n';
}

View File

@@ -0,0 +1,128 @@
/* Problem URL: https://codeforces.com/gym/104871/problem/E */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string op;
map<string, int> guys;
set<string> all;
while (getline(cin, op), op[0] != '-') {
int n, m;
char fds[21];
sscanf(op.c_str(), "%d%d%s", &n, &m, fds);
string act = fds;
guys[act] += m - n;
all.insert(act);
}
map<string, int> other;
while (getline(cin, op), op[0] != '=') {
int n, m;
char fds[21];
sscanf(op.c_str(), "%d%d%s", &n, &m, fds);
string act = fds;
other[act] += m - n;
all.insert(act);
}
int s = 0;
for (auto &i : all) {
int diff = other[i] - guys[i];
if (diff == 0) {
s++;
continue;
}
cout << i << ' ';
if (diff > 0) {
cout << "+" << diff << '\n';
continue;
}
cout << diff << '\n';
}
if (s == all.size()) {
cout << "No differences found.\n";
}
}

View File

@@ -0,0 +1,263 @@
/* Problem URL: https://codeforces.com/gym/104871/problem/G */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
using ld = long double;
ld EPS = 1e-16L;
bool eq(ld a, ld b) {
return abs(a - b) <= EPS;
}
struct pt {
ld x, y;
pt(ld x = 0, ld y = 0): x(x), y(y) {}
ld operator^(const pt p) const {
return x*p.y - y*p.x;
}
pt operator-(const pt p) const {
return {x - p.x, y - p.y};
}
ld operator*(const pt p) const {
return x*p.x + y*p.y;
}
friend istream& operator >> (istream& in, pt &p) {
return in >> p.x >> p.y;
}
};
ld dist(pt p, pt q)
{
return hypot(p.y - q.y, p.x - q.x);
}
ld sarea(pt p, pt q, pt r)
{
return ((q-p)^(r-q)) / 2;
}
struct line {
pt p, q;
line() {}
line (pt p, pt q): p(p), q(q) {}
};
bool ccw(pt p, pt q, pt r)
{
return sarea(p, q, r) > EPS;
}
ld disttoline(pt p, line r)
{
return 2 * abs(sarea(p, r.p, r.q)) / dist(r.p, r.q);
}
bool isinseg(pt p, line r)
{
pt a = r.p - p, b = r.q - p;
return eq((a^b), 0) and (a * b) < EPS;
}
bool interseg(line r, line s)
{
if (isinseg(r.p, s) or isinseg(r.q, s) or isinseg(s.p, r) or isinseg(s.q, r)) {
return true;
}
return ccw(r.p, r.q, s.p) != ccw(r.p, r.q, s.q) and ccw(s.p, s.q, r.p) != ccw(s.p, s.q, r.q);
}
ld disttoseg(pt p, line r)
{
if ((r.q - r.p) * (p - r.p) < 0) {
return dist(r.p, p);
}
if ((r.p - r.q) * (p - r.q) < 0) {
return dist(r.q, p);
}
return disttoline(p, r);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
pt a, b;
pt cir;
ld r;
cin >> a >> b >> cir >> r;
if (eq(a.x, b.x) && eq(a.y, b.y)) {
ld dista = dist(a, cir);
if (dista <= r) {
cout << "0\n";
continue;
}
dista -= r;
cout << setprecision(12) << (dista - r) * 2 << '\n';
continue;
}
ld distret = disttoseg(cir, line(a, b));
cout << distret << '\n';
if (distret <= r) {
cout << setprecision(12) << dist(a, b) << '\n';
continue;
}
a.x -= cir.x;
a.y -= cir.y;
b.x -= cir.x;
b.y -= cir.y;
ld low = -r;
ld high = r;
ld ans = 1e18;
ld eps = 1e-9;
while (high - low >= eps) {
ld third = (high - low) / 3;
ld mid1 = low + third;
ld mid2 = high - third;
auto getans = [&](ld mid) {
ld one = (a.x - mid);
ld two = (a.y - sqrt(r * r - mid * mid));
ld ac = sqrt(one * one + two * two);
one = (b.x - mid);
two = (b.y - sqrt(r * r - mid * mid));
ac += sqrt(one * one + two * two);
return ac;
};
ld ans1 = getans(mid1);
ld ans2 = getans(mid2);
if (ans1 <= ans2) {
high = mid2;
ans = ans1;
continue;
}
low = mid1;
ans = ans2;
}
low = -r;
high = r;
while (high - low >= eps) {
ld third = (high - low) / 3;
ld mid1 = low + third;
ld mid2 = high - third;
auto getans = [&](ld mid) {
ld one = (a.x - mid);
ld two = (a.y + sqrt(r * r - mid * mid));
ld ac = sqrt(one * one + two * two);
one = (b.x - mid);
two = (b.y + sqrt(r * r - mid * mid));
ac += sqrt(one * one + two * two);
return ac;
};
ld ans1 = getans(mid1);
ld ans2 = getans(mid2);
if (ans1 <= ans2) {
high = mid2;
ans = ans1;
continue;
}
low = mid1;
ans = ans2;
}
cout << setprecision(12) << ans << '\n';
}
}

View File

@@ -0,0 +1,207 @@
/* Problem URL: https://codeforces.com/gym/104871/problem/H */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
void encode()
{
map<string, int> var;
V<string> inv;
int prev = -1;
string guy;
vvi graph;
V<bool> parentless;
while (cin >> guy) {
if (guy.back() == ':') {
guy.pop_back();
if (var.find(guy) == var.end()) {
graph.emplace_back();
inv.emplace_back(guy);
var[guy] = var.size();
parentless.push_back(true);
}
prev = var[guy];
continue;
}
if (var.find(guy) == var.end()) {
graph.emplace_back();
inv.emplace_back(guy);
var[guy] = var.size();
parentless.push_back(false);
}
int act = var[guy];
graph[prev].push_back(act);
parentless[act] = false;
}
int root = 0;
while (!parentless[root]) {
root++;
}
string bin;
vi ans;
function<void(int)> dfs = [&](int i) {
// for (auto j : graph[i]) {
// ans.push_back(j);
// bin.push_back('0');
// }
for (auto j : graph[i]) {
dfs(j);
}
for (auto j : graph[i]) {
bin.push_back('0');
}
bin.push_back('1');
ans.push_back(i);
};
dfs(root);
rep(i, ans.size()) {
cout << inv[ans[i]] << '\n';
}
// reverse(all(bin));
cout << bin << '\n';
}
void decode()
{
map<string, int> var;
V<string> inv;
string bin;
while (cin >> bin, !isdigit(bin[0])) {
var[bin] = var.size();
inv.emplace_back(bin);
}
vvi ans(var.size());
stack<int> q;
int i = 0;
rep(cur, bin.size()) {
if (bin[cur] == '1') {
q.push(i);
i++;
continue;
}
ans[i].push_back(q.top());
q.pop();
}
i = ans.size();
while (i--) {
if (ans[i].empty()) {
continue;
}
cout << inv[i] << ": ";
reverse(all(ans[i]));
repv(j, ans[i]) {
cout << inv[j] << ' ';
}
cout << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string op;
cin >> op;
if (op == "ENCODE") {
encode();
} else {
decode();
}
}

View File

@@ -0,0 +1,121 @@
/* Problem URL: https://codeforces.com/gym/104871/problem/L */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string op;
map<string, int> guys;
set<string> all;
while (getline(cin, op), op[0] != '-') {
int n, m;
char fds[21];
sscanf(op.c_str(), "%d%d%s", &n, &m, fds);
string act = fds;
guys[act] += m - n;
all.insert(act);
}
map<string, int> other;
while (getline(cin, op), op[0] != '-') {
int n, m;
char fds[21];
sscanf(op.c_str(), "%d%d%s", &n, &m, fds);
string act = fds;
other[act] += n - m;
all.insert(act);
}
for (auto &i : all) {
int diff = guys[i] - other[i];
if (diff == 0) {
continue;
}
cout << i << ' ';
if (diff > 0) {
cout << "+" << diff << '\n';
continue;
}
cout << diff << '\n';
}
}