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,170 @@
/* Problem URL: https://codeforces.com/gym/104020/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;
}
#define double long double
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string a, b;
cin >> a >> b;
double ang1;
double ang2;
map<string, double> var;
var["N"] = 0;
var["E"] = 90;
var["S"] = 180;
var["W"] = 270;
var["NE"] = 45;
var["SE"] = 135;
var["SW"] = 225;
var["NW"] = 315;
if (a.size() == 1) {
ang1 = var[a];
} else {
ang1 = var[a.substr(a.size() - 2)];
map<char, double> mul;
mul['W'] = 1;
mul['E'] = 1;
mul['S'] = 1;
mul['N'] = 1;
string tmp = a.substr(a.size() - 2);
if (tmp == "NE") {
mul['N'] = -1;
} else if (tmp == "SE") {
mul['E'] = -1;
} else if (tmp == "SW") {
mul['S'] = -1;
} else {
mul['W'] = -1;
}
a.pop_back();
a.pop_back();
double now = 45 / (double)2;
while (!a.empty()) {
ang1 += now * mul[a.back()];
a.pop_back();
now /= 2;
}
}
if (b.size() == 1) {
ang2 = var[b];
} else {
ang2 = var[b.substr(b.size() - 2)];
map<char, double> mul;
mul['W'] = 1;
mul['E'] = 1;
mul['S'] = 1;
mul['N'] = 1;
string tmp = b.substr(b.size() - 2);
if (tmp == "NE") {
mul['N'] = -1;
} else if (tmp == "SE") {
mul['E'] = -1;
} else if (tmp == "SW") {
mul['S'] = -1;
} else {
mul['W'] = -1;
}
b.pop_back();
b.pop_back();
double now = 45 / (double)2;
while (!b.empty()) {
ang2 += now * mul[b.back()];
b.pop_back();
now /= 2;
}
}
if (ang1 < ang2) {
swap(ang1, ang2);
}
cout << fixed << setprecision(20) << min(ang1 - ang2, (ang2 - ang1) + 360) << '\n';
}

View File

@@ -0,0 +1,124 @@
/* Problem URL: https://codeforces.com/gym/104020/problem/J */
#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);
ll w, h;
cin >> w >> h;
vi columns(w);
rep(i, w) {
columns[i] = i;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
shuffle(all(columns), rng);
ll ansx = 1;
ll ansy = 0;
repv(i, columns) {
if (ansy == h) {
break;
}
cout << "? " << i + 1 << ' ' << ansy + 1 << endl;
string a;
cin >> a;
if (a == "sky") {
continue;
}
ll low = ansy + 1;
ll high = h;
while (low <= high) {
ll mid = (high - low) / 2 + low;
cout << "? " << i + 1 << ' ' << mid << endl;
cin >> a;
if (a == "building") {
ansy = mid;
ansx = i + 1;
low = mid + 1;
continue;
}
high = mid - 1;
}
}
cout << "! " << ansx << ' ' << ansy << endl;
}

View File

@@ -0,0 +1,182 @@
/* Problem URL: https://codeforces.com/gym/104020/problem/K */
#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, m;
cin >> n >> m;
set<int> attempts;
for (int i = 1; i <= n * m; i++) {
attempts.insert(i);
}
vvi fds(n, vi(m));
cin >> fds;
auto choice = [&](int i, int j, int t) {
int add[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int ans = INT32_MAX >> 1;
for (auto &k : add) {
int id = i + k[0];
int jd = j + k[1];
if (id >= 0 && id < n && jd >= 0 && jd < m) {
int now = fds[id][jd];
if (abs(t - now) < abs(t - ans) || (abs(t - now) == abs(t - ans) && abs(fds[i][j] - now) < abs(fds[i][j] - ans))) {
ans = now;
}
}
}
return ans;
};
vvvi graph(n * m, vvi(n * m));
vvvi look(n * m, vvi(n * m));
for (int i = 1; i <= n * m; i++) {
rep(j, n) {
rep(k, m) {
if (fds[j][k] == i) {
continue;
}
int tmp = choice(j, k, i);
graph[i - 1][tmp - 1].push_back(fds[j][k] - 1);
look[i - 1][fds[j][k] - 1].push_back(tmp - 1);
}
}
}
vvi depth(n * m, vi(n * m, 0));
V<bool> vis(n * m);
function<void(int, int, int)> dfs = [&](int i, int t, int d) {
vis[i] = true;
depth[i][t] = d;
for (auto j : graph[t][i]) {
if (vis[j]) {
continue;
}
dfs(j, t, d + 1);
}
};
rep(i, n * m) {
fill(all(vis), false);
dfs(i, i, 0);
auto itr = attempts.begin();
while (itr != attempts.end()) {
if (!vis[*itr]) {
itr = attempts.erase(itr);
} else {
itr++;
}
}
if (attempts.empty()) {
break;
}
}
if (attempts.empty()) {
cout << "impossible\n";
return 0;
}
int ans = 0;
int minimal = INT32_MAX >> 1;
for (auto i : attempts) {
int get = 0;
for (auto j : depth[i]) {
rmax(get, j);
}
if (get < minimal) {
ans = i;
minimal = get;
}
}
cout << ans + 1 << ' ' << minimal << '\n';
}