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,224 @@
/* Problem URL: https://codeforces.com/group/btcK4I5D5f/contest/601720/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 (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t 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 fact(ll n)
{
if (n == 1) {
return n;
}
return n * fact(n - 1);
}
ll fastpow(ll n, ll p)
{
ll ans = 1;
ll power = n % 10;
for (size_t i = 0; i <= 100; i++) {
if (p & ((__int128)1 << i)) {
ans *= power;
ans %= 10;
}
power *= power;
power %= 10;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll no;
cin >> no;
__int128 n = no;
__int128 n2 = 0;
__int128 n3 = 0;
__int128 n4 = 0;
__int128 n5 = 0;
__int128 n6 = 0;
__int128 n7 = 0;
__int128 n8 = 0;
__int128 n9 = 0;
for (__int128 i = 10; i <= n * (__int128)10; i *= 10) {
if (n / (i / 10) % 10 >= 2) {
n2 += n / i + 1;
} else {
n2 += n / i;
}
if (n / (i / 10) % 10 >= 3) {
n3 += n / i + 1;
} else {
n3 += n / i;
}
if (n / (i / 10) % 10 >= 4) {
n4 += n / i + 1;
} else {
n4 += n / i;
}
if (n / (i / 10) % 10 >= 5) {
n5 += n / i + 1;
} else {
n5 += n / i;
}
if (n / (i / 10) % 10 >= 6) {
n6 += n / i + 1;
} else {
n6 += n / i;
}
if (n / (i / 10) % 10 >= 7) {
n7 += n / i + 1;
} else {
n7 += n / i;
}
if (n / (i / 10) % 10 >= 8) {
n8 += n / i + 1;
} else {
n8 += n / i;
}
if (n / (i / 10) % 10 >= 9) {
n9 += n / i + 1;
} else {
n9 += n / i;
}
}
// cout << n2 << ' ' << n3 << ' ' << n4 << ' ' << n5 << ' ' << n6 << ' ' << n7 << ' ' << n8 << ' ' << n9 << '\n';
n5 = 0;
for (__int128 i = 5; i <= n; i *= 5) {
for (__int128 j = 1; i * j <= n; j *= 10) {
__int128 tmp = n / (i * j);
// n2 += tmp / 10;
// if (tmp % 10 >= 2) {
// n2++;
// }
n3 += tmp / 10;
if (tmp % 10 >= 3) {
n3++;
}
// n4 += tmp / 10;
// if (tmp % 10 >= 4) {
// n4++;
// }
n6 += tmp / 10;
if (tmp % 10 >= 6) {
n6++;
}
n7 += tmp / 10;
if (tmp % 10 >= 7) {
n7++;
}
// n8 += tmp / 10;
// if (tmp % 10 >= 8) {
// n8++;
// }
n9 += tmp / 10;
if (tmp % 10 >= 9) {
n9++;
}
}
n5 += n / i;
}
for (__int128 i = 10; i <= n; i *= 10) {
n5 -= n / i;
}
// cout << n2 << ' ' << n3 << ' ' << n4 << ' ' << n5 << ' ' << n6 << ' ' << n7 << ' ' << n8 << ' ' << n9 << '\n';
n2 -= n5;
if (n2 < 0) {
ll diff = -n2;
n2 = diff;
n4 -= diff;
}
// n2 += n10;
// cout << n2 << ' ' << n3 << ' ' << n4 << ' ' << n5 << ' ' << n6 << ' ' << n7 << ' ' << n8 << ' ' << n9 << '\n';
ll ans = fastpow(2, n2);
ans %= 10;
ans *= fastpow(3, n3);
ans %= 10;
ans *= fastpow(4, n4);
ans %= 10;
ans *= fastpow(6, n6);
ans %= 10;
ans *= fastpow(7, n7);
ans %= 10;
ans *= fastpow(8, n8);
ans %= 10;
ans *= fastpow(9, n9);
ans %= 10;
cout << ans << '\n';
}

View File

@@ -0,0 +1,160 @@
/* Problem URL: https://codeforces.com/group/btcK4I5D5f/contest/601720/problem/M */
#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 (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t 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, k, m;
cin >> n >> k >> m;
vvi dp(51, vi(m + 1, 0));
rep(i, 51) {
nrep(j, 1, m + 1) {
if (i <= k) {
dp[i][j] = i;
continue;
}
rep(k, j) {
rmax(dp[i][j], dp[i / 2][k] + dp[i / 2 + i % 2][j - k - 1]);
}
}
}
vi mangas(n);
cin >> mangas;
vvi dp2(n + 1, vi(m + 1, 0));
rep(i, n) {
nrep(j, 1, m + 1) {
rep(k, j + 1) {
rmax(dp2[i + 1][j], dp2[i][k] + dp[mangas[i]][j - k]);
}
rmax(dp2[i + 1][j], dp2[i][j]);
}
}
V<pair<int, int>> ops;
function<void(int, int)> getops = [&](int manga, int j){
if (j == 0) {
return;
}
if (manga <= k) {
ops.emplace_back(1, manga);
return;
}
rep(i, j) {
if (dp[manga / 2][i] + dp[manga / 2 + manga % 2][j - i - 1] == dp[manga][j]) {
ops.emplace_back(2, manga);
getops(manga / 2, i);
getops(manga / 2 + manga % 2, j - i - 1);
return;
}
}
};
auto recover = [&](){
int i = n;
int j = m;
while (j > 0 && i > 0 && dp2[i][j] > 0) {
while (dp2[i - 1][j] == dp2[i][j]) {
i--;
}
while (dp2[i][j - 1] == dp2[i][j]) {
j--;
}
rep(k, j) {
if (dp2[i - 1][k] + dp[mangas[i - 1]][j - k] == dp2[i][j]) {
getops(mangas[i - 1], j - k);
j = k;
i--;
break;
}
}
}
};
recover();
cout << dp2.back().back() << ' ' << ops.size() << '\n';
for (auto [i, j] : ops) {
cout << i << ' ' << j << '\n';
}
}

View File

@@ -0,0 +1,121 @@
/* Problem URL: https://codeforces.com/group/btcK4I5D5f/contest/601720/problem/N */
#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 (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t 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 m;
cin >> m;
if (m == 1) {
int n;
cin >> n;
string a;
cin >> a;
a += a;
char sum = 0;
rep(i, n) {
sum = (sum + a[i] - 'a') % 26;
}
a.push_back(sum + 'a');
sum = 0;
nrep(i, n, n * 2) {
sum = (sum + a[i] - 'a') % 26;
}
a.push_back(sum + 'a');
cout << a << '\n';
} else {
int n;
cin >> n;
string a;
cin >> a;
n = (n - 2) / 2;
string a1 = a.substr(0, n);
string a2 = a.substr(n, n);
int p1 = a[n * 2] - 'a';
int test = 0;
repv(i, a1) {
test = (test + i - 'a') % 26;
}
if (test == p1) {
cout << a1 << '\n';
return 0;
}
cout << a2 << '\n';
}
}