Add a bunch of other problems.

Some are not finished...
This commit is contained in:
2025-09-12 14:50:25 -03:00
parent 88e542c982
commit 489cb2ba51
385 changed files with 49442 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
/* Problem URL: https://codeforces.com/gym/105900/problem/B */
#include <bits/stdc++.h>
using namespace std;
#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;
}
ll mod = 1e9 + 7;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, k;
cin >> n >> k;
ll ans = 0;
if (k & 1) {
ans = 1;
}
ll power = n;
nrep(i, 1, 31) {
if ((k >> i) & 1){
ans += power;
ans %= mod;
}
power *= n;
power %= mod;
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,91 @@
/* Problem URL: https://codeforces.com/gym/105900/problem/D */
#include <bits/stdc++.h>
using namespace std;
#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;
}
const long double pi = numbers::pi;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
long double rl, hl, rc, hc;
cin >> rl >> hl >> rc >> hc;
long double vol1 = pi * rl * rl * hl;
long double vol2 = pi * hc * rc * rc / 3;
long double vol3 = pi * rc * rc * rc * 2 / 3;
if (vol1 > (vol2 + vol3)) {
cout << "Injusto\n";
} else {
cout << "Justo\n";
}
}

View File

@@ -0,0 +1,147 @@
/* Problem URL: https://codeforces.com/gym/105900/problem/E */
#include <bits/stdc++.h>
using namespace std;
#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;
}
ll mod = 1e9 + 7;
int s = 27;
vvl operator*(vvl &a, vvl &b)
{
vvl ans(s, vl(s));
rep(i, s) {
rep(j, s) {
rep(k, s) {
ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % mod;
}
}
}
return ans;
}
vvl exponential(ll n)
{
vvl ans(s, vl(s));
rep(i, s) {
ans[i][i] = 1;
}
vvl expc(s, vl(s));
// expc[0][0] = 1;
nrep(i, 1, s) {
expc[i][i] = i;
expc[i][i - 1] = 1;
}
rep(i, 60) {
if ((n >> i) & 1) {
ans = ans * expc;
}
expc = expc * expc;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
// vl trans(26);
// trans[0] = 1;
// nrep(i, 1, n) {
// for (int j = 25; j > 0; j--) {
// trans[j] = trans[j] * (j + 1) + trans[j - 1];
// trans[j] %= mod;
// }
// }
//
// ll total = 0;
// repv(i, trans) {
// total += i;
// total %= mod;
// }
//
vvl ans = exponential(n);
ll total = 0;
rep(i, s) {
total += ans[i][0];
total %= mod;
}
cout << total << '\n';
}

View File

@@ -0,0 +1,195 @@
/* Problem URL: https://codeforces.com/gym/105900/problem/F */
#include <bits/stdc++.h>
using namespace std;
#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;
}
template<typename T> tuple<T, T, T> ext_gcd(T a, T b) {
if (!a) return {b, 0, 1};
auto [g, x, y] = ext_gcd(b%a, a);
return {g, y - b/a*x, x};
}
template<typename T = ll> struct crt {
T a, m;
crt() : a(0), m(1) {}
crt(T a_, T m_) : a(a_), m(m_) {}
crt operator * (crt C) {
auto [g, x, y] = ext_gcd(m, C.m);
if ((a - C.a) % g) a = -1;
if (a == -1 or C.a == -1) return crt(-1, 0);
T lcm = m/g*C.m;
T ans = a + (x*(C.a-a)/g % (C.m/g))*m;
return crt((ans % lcm + lcm) % lcm, lcm);
}
};
ll tot(int n) {
ll ret = n;
for (int i = 2; i*i <= n; i++) if (n % i == 0) {
while (n % i == 0) n /= i;
ret -= ret / i;
}
if (n > 1) ret -= ret / n;
return ret;
}
ll fastpow(ll a, ll b, ll tot)
{
ll ans = 1;
ll now = a;
for (int i = 0; i < 31; i++) {
if ((b >> i) & 1) {
ans *= now;
ans %= tot;
}
now *= now;
now %= tot;
}
return ans;
}
vvl mul(vvl &a, vvl &b, ll mod)
{
vvl ans(a.size(), vl(b[0].size()));
rep(i, a.size()) {
rep(j, b[0].size()) {
rep(k, a[0].size()) {
ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % mod;
}
}
}
return ans;
}
ll binaryexpo(ll pow, ll mod)
{
vvl ans = {
{1, 0},
{0, 0}
};
if (pow <= 1) {
return pow;
}
pow--;
vvl now = {
{1, 1},
{1, 0}
};
rep(i, 62) {
if ((pow >> i) & 1) {
ans = mul(ans, now, mod);
}
now = mul(now, now, mod);
}
return ans[0][0];
}
ll factor(ll n)
{
ll sqr = sqrt(n);
for (ll i = 2; i <= sqr; i++) {
if (n % i == 0) {
return i;
}
}
return n;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll a, b, m;
cin >> a >> b >> m;
ll mtot = tot(m);
if (__gcd(a, m) != 1) {
ll tmp = factor(mtot);
crt one(fastpow(a, b, tmp), tmp);
crt two(fastpow(a, b, mtot / tmp), mtot / tmp);
mtot = (one * two).m;
}
cout << binaryexpo(fastpow(a, b, mtot), m) << '\n';
}

View File

@@ -0,0 +1,147 @@
/* Problem URL: https://codeforces.com/gym/105900/problem/G */
#include <bits/stdc++.h>
using namespace std;
#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);
int n;
cin >> n;
vi fds(n);
repv(i, fds) {
cin >> i;
i--;
}
vvi dp(n, vi(2, -1));
int ans = 0;
V<bool> frame(n);
V<bool> vis(n);
vi dis(n, 0);
V<bool> loop(n);
function<pair<int, int>(int)> dfs = [&](int i) {
vis[i] = true;
if (frame[fds[i]]) {
int size = dis[i] - dis[fds[i]];
dp[i][0] = size / 2;
dp[i][1] = size / 2;
loop[i] = true;
return make_pair(fds[i], size);
}
frame[i] = true;
dis[fds[i]] = dis[i] + 1;
auto [cat, size] = dfs(fds[i]);
frame[i] = false;
if (cat != -1) {
loop[i] = true;
dp[i][0] = ans / 2;
dp[i][1] = ans / 2;
if (cat == i) {
return make_pair(-1, -1);
}
return make_pair(cat, size);
}
return make_pair(-1, -1);
};
rep(i, n) {
if (vis[i]) {
continue;
}
dfs(i);
}
function<void(int)> calc = [&](int i) {
if (dp[i][0] != -1) {
return;
}
dp[i][0] = dp[fds[i]][1];
dp[i][1] = dp[fds[i]][0] + 1;
};
rep(i, n) {
}
cout << dp;
cout << ans << '\n';
}