Compare commits

..

26 Commits

Author SHA1 Message Date
e9cafa367b More problems 2026-03-19 16:00:45 -03:00
14deae4d42 Add another problem in problemlist 2026-03-17 15:33:23 -03:00
07afa2b2a8 Add more problems 2026-03-17 15:17:32 -03:00
ccd62bc6e9 Merge branch 'master' of https://git.puffypony.party/segcolt/codeforces-solutions 2026-03-16 20:17:00 -03:00
23630c1356 Add a bunch more stuff 2026-03-16 20:14:14 -03:00
2d314df46f A bunch new problems 2026-03-16 17:09:23 -03:00
41d9ca1dc8 Merge branch 'master' of https://git.puffypony.party/segcolt/codeforces-solutions 2026-02-23 15:34:27 -03:00
43ced801b4 Add some more problems from a little simulation 2026-02-23 15:33:39 -03:00
3174264022 More stuff 2026-02-22 22:39:00 -03:00
acabee731f More stuff 2026-02-21 14:00:11 -03:00
c2a0f3e0db More stuff 2026-02-21 13:55:51 -03:00
eccccddcc8 Add more problems 2026-02-14 12:32:06 -03:00
05414bf7f7 Add more problems. 2026-01-16 17:50:50 -03:00
28bb38c1f8 Add a problem list 2025-12-15 13:41:06 -03:00
c4acd23d19 Add a bunch of other problems. 2025-12-15 13:40:39 -03:00
97ebdbf890 Add some more problems and update TODO list 2025-10-30 17:11:49 -03:00
cf5a83fb09 Fix TODO list 2025-10-18 16:59:08 -03:00
f3275cd442 Add a lot more problems and a TODO list 2025-10-18 16:54:05 -03:00
Segcolt
f82c3630cf Another educational 2025-10-03 16:10:48 -03:00
2a214d9f86 I hate myself 2025-10-02 18:06:01 -03:00
e3421b4066 Add a bunch of other problems 2025-10-01 10:35:36 -03:00
489cb2ba51 Add a bunch of other problems.
Some are not finished...
2025-09-12 14:50:25 -03:00
88e542c982 Change the solution to be more simple.
The logic was much more simple than what I could have thought on the
contest...
2024-11-17 16:16:54 -03:00
fddaaeba59 Finally do another div3 again.
I'm getting rusty...
2024-11-17 13:36:44 -03:00
48a13b9262 Finish this hellish problem
Holy crap... Memory limit gallore, I had to make a LOT of optimizations
on this one, and it just barely worked...
2024-10-24 14:45:14 -03:00
337b443085 Make a single problem from div3
I didn't actually submit this one, I just got tired and gave up on the
div... I'll simulate it later.
2024-10-24 14:44:38 -03:00
895 changed files with 124897 additions and 0 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,6 @@
*
!/*/
!*.cpp
!TODO.md
!problemlist.md
*sync-conflict*

View File

@@ -0,0 +1,144 @@
/* Problem URL: https://codeforces.com/gym/100886/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);
string tmp, b;
cin >> tmp >> b;
size_t diff = b.size() - tmp.size();
string a;
rep(i, diff) {
a.push_back('0');
}
a += tmp;
rep(i, a.size()) {
if (a[i] != b[i]) {
break;
}
if (a[i] == '0') {
cout << b << '\n';
return 0;
}
}
vvvvl memo(a.size(), vvvl(2, vvl(2, vl(2, -1))));
function<ll(int, int, int, int)> dp = [&](int i, int over, int under, int started) -> ll {
if (i >= a.size()) {
return 1;
}
ll &ans = memo[i][over][under][started];
if (ans != -1) {
return ans;
}
ans = 0;
char limit = over ? '0' : a[i];
for (int j = under ? '9' : b[i]; j >= limit; j--) {
rmax(ans, dp(i + 1, over || j > a[i], under || j < b[i], started || j != '0') * (!started && j == '0' ? 1 : j - '0'));
}
return ans;
};
ll res = dp(0, 0, 0, 0);
string ans;
function<void(int, int, int, int, ll)> recover = [&](int i, int over, int under, int started, ll prod) {
if (i >= a.size() - 1) {
ans.push_back(prod + '0');
return;
}
char limit = over ? '0' : a[i];
for (int j = under ? '9' : b[i]; j >= limit; j--) {
ll div = !started && j == '0' ? 1 : j - '0';
if (prod % div == 0 && memo[i + 1][over || j > a[i]][under || j < b[i]][started || j != '0'] == prod / div) {
ans.push_back(j);
recover(i + 1, over || j > a[i], under || j < b[i], started || j != '0', prod / div);
return;
}
}
};
recover(0, 0, 0, 0, res);
cout << stoll(ans) << '\n';
}

View File

@@ -0,0 +1,152 @@
/* Problem URL: https://codeforces.com/gym/102114/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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
int n, m;
unsigned x, y, z;
cin >> n >> m >> x >> y >> z;
auto rng = [&]() {
x = x ^ (x << 11);
x = x ^ (x >> 4);
x = x ^ (x << 5);
x = x ^ (x >> 14);
unsigned w = x ^ y ^ z;
x = y;
y = z;
z = w;
return z;
};
vvl sparse(20, vl(n));
while (m--) {
ll rng1 = rng();
ll rng2 = rng();
ll rng3 = rng();
int l = min(rng2 % n + 1, rng1 % n + 1);
int r = max(rng2 % n + 1, rng1 % n + 1);
ll val = rng3 & ((1LL << 30) - 1);
l--, r--;
int log = 31 - __builtin_clz(r - l + 1);
rmax(sparse[log][l], val);
rmax(sparse[log][r - (1 << log) + 1], val);
}
for (int j = 19; j > 0; j--) {
for (int i = 0; i + (1 << (j - 1)) < n; i++) {
rmax(sparse[j - 1][i], sparse[j][i]);
rmax(sparse[j - 1][i + (1 << (j - 1))], sparse[j][i]);
}
}
ll ans = 0;
rep(i, n) {
ans ^= (i + 1) * sparse[0][i];
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,78 @@
/* Problem URL: https://codeforces.com/gym/102021/problem/A */
#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);
}

View File

@@ -0,0 +1,134 @@
/* Problem URL: https://codeforces.com/gym/101908/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int mr;
cin >> mr;
const int n = 101;
const int inf = INT32_MAX >> 1;
vvi grundy(n, vi(n));
rep(i, n) {
grundy[i][i] = 1000;
grundy[0][i] = 1000;
grundy[i][0] = 1000;
}
auto search = [&](int i, int j) {
V<bool> exists(1001, false);
nrep(k, 1, n) {
if (i - k >= 0) {
exists[grundy[i - k][j]] = true;
}
if (j - k >= 0) {
exists[grundy[i][j - k]] = true;
}
if (i - k >= 0 && j - k >= 0) {
exists[grundy[i - k][j - k]] = true;
}
}
int mex = 0;
while (exists[mex]) {
mex++;
}
return mex;
};
nrep(i, 1, n) {
nrep(j, 1, n) {
if (i == j) {
continue;
}
grundy[i][j] = search(i, j);
}
}
int state = 0;
while (mr--) {
int i, j;
cin >> i >> j;
state ^= grundy[i][j];
}
cout << (state == 0 ? "N\n" : "Y\n");
}

View File

@@ -0,0 +1,156 @@
/* Problem URL: https://codeforces.com/gym/101908/problem/C */
#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);
ll x, y;
cin >> x >> y;
ll h, v;
cin >> h >> v;
ll ans = (h + 1) * (v + 1);
V<pair<ll, ll>> ys(h);
repv(i, ys) {
cin >> i.first >> i.second;
}
V<pair<ll, ll>> xs(v);
repv(i, xs) {
cin >> i.first >> i.second;
}
sortv(ys);
sortv(xs);
function<ll(V<pair<ll, ll>>&)> count = [&](V<pair<ll, ll>> &vec) -> ll {
if (vec.size() <= 1) {
return 0;
}
int mid = vec.size() / 2;
V<pair<ll, ll>> first(mid);
rep(i, mid) {
first[i] = vec[i];
}
V<pair<ll, ll>> second(vec.size() - mid);
rep(i, vec.size() - mid) {
second[i] = vec[vec.size() - i - 1];
}
reverse(all(second));
ll ans = count(first);
ans += count(second);
int now = 0;
int l = 0;
int r = 0;
while (l < first.size() && r < second.size()) {
if (first[l].second <= second[r].second) {
vec[now] = first[l];
now++;
l++;
continue;
}
ans += first.size() - l;
vec[now] = second[r];
now++;
r++;
}
while (l < first.size()) {
vec[now] = first[l];
l++;
now++;
}
while (r < second.size()) {
vec[now] = second[r];
r++;
now++;
}
return ans;
};
ans += count(xs);
ans += count(ys);
cout << ans << '\n';
}

View File

@@ -0,0 +1,89 @@
/* Problem URL: https://codeforces.com/gym/101908/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
int count = 0;
while (t--) {
int n;
cin >> n;
if (n == 2 || n == 3) {
count++;
}
}
cout << count << '\n';
}

View File

@@ -0,0 +1,97 @@
/* Problem URL: https://codeforces.com/gym/101908/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string a, b;
cin >> a >> b;
int count = 0;
rep(i, a.size() - b.size() + 1) {
bool pos = true;
rep(j, b.size()) {
if (a[i + j] == b[j]) {
pos = false;
break;
}
}
if (pos) {
count++;
}
}
cout << count << '\n';
}

View File

@@ -0,0 +1,81 @@
/* Problem URL: https://codeforces.com/gym/101908/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
V<tuple<int, int, int, int>> stuff;
}

View File

@@ -0,0 +1,120 @@
/* Problem URL: https://codeforces.com/gym/101908/problem/I */
#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, m;
cin >> n >> m;
int l;
cin >> l;
int on = l;
vi status(m);
while (l--) {
int a;
cin >> a;
status[a - 1] = 1;
}
vvi graph(n);
rep(i, n) {
int k;
cin >> k;
while (k--) {
int b;
cin >> b;
graph[i].push_back(b - 1);
}
}
int i = 0;
while (i < 2 * n && on != 0) {
repv(j, graph[i % n]) {
on += 1 - 2 * status[j];
status[j] ^= 1;
}
i++;
}
if (on != 0) {
cout << "-1\n";
return 0;
}
cout << i << '\n';
}

View File

@@ -0,0 +1,159 @@
/* Problem URL: https://codeforces.com/gym/101908/problem/L */
#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, q;
cin >> n >> q;
vvi graph(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vvi parent(n, vi(20, 0));
vi depth(n, 0);
function<void(int, int)> dfs = [&](int i, int p) {
depth[i] = depth[p] + 1;
parent[i][0] = p;
nrep(j, 1, 20) {
parent[i][j] = parent[parent[i][j - 1]][j - 1];
}
for (auto j : graph[i]) {
if (j == p) {
continue;
}
dfs(j, i);
}
};
dfs(0, 0);
auto lca = [&](int a, int b) {
if (depth[a] > depth[b]) {
swap(a, b);
}
int diff = depth[b] - depth[a];
rep(i, 20) {
if ((diff >> i) & 1) {
b = parent[b][i];
}
}
if (a == b) {
return a;
}
for (int i = 19; i >= 0; i--) {
if (parent[a][i] != parent[b][i]) {
a = parent[a][i];
b = parent[b][i];
}
}
return parent[a][0];
};
auto dis = [&](int a, int b) {
return depth[a] + depth[b] - 2 * depth[lca(a, b)];
};
while (q--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
a--, b--, c--, d--;
int x = dis(a, b) + dis(c, d);
int y = min(dis(a, c) + dis(b, d), dis(a, d) + dis(b, c));
if (y > x) {
cout << "0\n";
continue;
}
cout << (x - y) / 2 + 1 << '\n';
}
}

View File

@@ -0,0 +1,302 @@
/* Problem URL: https://codeforces.com/gym/102361/problem/A */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
struct pt {
ll x, y;
pt() = default;
pt(ll x, ll y): x(x), y(y) {}
friend istream &operator >> (istream &is, pt &a) {
is >> a.x >> a.y;
return is;
}
ll operator ^ (pt b) {
return x * b.y - y * b.x;
}
ll operator * (pt b) {
return x * b.x + y * b.y;
}
pt operator - (pt b) {
return pt(x - b.x, y - b.y);
}
};
int ccw(pt a, pt b, pt c)
{
ll r = (b - a) ^ (c - a);
return (r > 0) - (r < 0);
}
ll cdot(pt a, pt b, pt c)
{
return (b - a) * (c - a);
}
int quad(pt a)
{
if (a.x == 0 && a.y > 0) {
return 0;
}
if (a.x > 0 && a.y == 0) {
return 1;
}
if (a.x == 0 && a.y < 0) {
return 2;
}
if (a.x < 0 && a.y == 0) {
return 3;
}
static const int q[][2] = {{0, 1}, {3, 2}};
return q[a.x < 0][a.y < 0];
}
bool polar_cmp(pt a, pt b)
{
if (quad(a) != quad(b)) {
return quad(a) != quad(b);
}
return ccw(pt(0, 0), a, b) < 0;
}
void pre()
{
}
#define TEST 0
void solve()
{
int n, q;
cin >> n >> q;
V<pt> pts(n + q);
cin >> pts;
vi p(n + q);
iota(all(p), 0);
auto cmpr = [&](vi &p, int i) {
if (p.empty()) {
return vector<pair<int, ll>>();
}
sort(all(p), [&](int j, int k){return polar_cmp(pts[j] - pts[i], pts[k] - pts[i]);});
V<pair<int, ll>> v;
int c = 1;
nrep(j, 1, p.size()) {
if (ccw(pts[i], pts[p[j]], pts[p[j - 1]]) == 0) {
c++;
continue;
}
v.emplace_back(p[j - 1], c);
c = 1;
}
v.emplace_back(p.back(), c);
return v;
};
vl ans(q);
rep(i, n) {
vvi qp(4);
nrep(j, n, n + q) {
qp[quad(pts[j] - pts[i])].push_back(j);
}
vvi np(4);
rep(j, n) {
if (i == j) {
continue;
}
np[quad(pts[j] - pts[i])].push_back(j);
}
V<V<pair<int, ll>>> cp = {cmpr(np[0], i), cmpr(np[1], i), cmpr(np[2], i), cmpr(np[3], i)};
auto cmp = [&](int j, int k) {
return polar_cmp(pts[j] - pts[i], pts[k] - pts[i]);
};
sort(all(qp[0]), cmp);
sort(all(qp[1]), cmp);
sort(all(qp[2]), cmp);
sort(all(qp[3]), cmp);
auto getcw = [&](vi &p, V<pair<int, ll>> &c) {
int j = 0;
int k = 0;
while (j < p.size() && k < c.size()) {
ll dot = cdot(pts[i], pts[p[j]], pts[c[k].first]);
if (dot == 0) {
ans[p[j] - n] += c[k].second;
j++;
continue;
}
if (dot > 0) {
k++;
continue;
}
j++;
}
};
auto getccw = [&](vi &p, V<pair<int, ll>> &c) {
int j = (int)p.size() - 1;
int k = (int)c.size() - 1;
while (j >= 0 && k >= 0) {
ll dot = cdot(pts[i], pts[p[j]], pts[c[k].first]);
if (dot == 0) {
ans[p[j] - n] += c[k].second;
j--;
continue;
}
if (dot > 0) {
k--;
continue;
}
j--;
}
};
rep(j, 4) {
getcw(qp[j], cp[(j + 1) % 4]);
getccw(qp[j], cp[((j - 1) % 4 + 4) % 4]);
}
}
nrep(i, n, n + q) {
vvi np(4);
rep(j, n) {
np[quad(pts[j] - pts[i])].push_back(j);
}
V<V<pair<int, ll>>> cp = {cmpr(np[0], i), cmpr(np[1], i), cmpr(np[2], i), cmpr(np[3], i)};
auto getcw = [&](V<pair<int, ll>> &p1, V<pair<int, ll>> &p2) {
int j = 0;
int k = 0;
while (j < p1.size() && k < p2.size()) {
ll dot = cdot(pts[i], pts[p1[j].first], pts[p2[k].first]);
if (dot == 0) {
ans[i - n] += p1[j].second * p2[k].second;
j++;
k++;
continue;
}
if (dot < 0) {
j++;
continue;
}
k++;
}
};
rep(j, 4) {
getcw(cp[j], cp[(j + 1) % 4]);
}
}
repv(i, ans) {
cout << i << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,223 @@
/* Problem URL: https://codeforces.com/gym/102361/problem/A */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
struct pt {
ll x, y;
pt() = default;
pt(ll x, ll y): x(x), y(y) {}
friend istream &operator >> (istream &is, pt &a) {
is >> a.x >> a.y;
return is;
}
pt operator - (pt b) {
return pt(x - b.x, y - b.y);
}
ll operator ^ (pt b) {
return x * b.y - y * b.x;
}
ll operator * (pt b) {
return x * b.x + y * b.y;
}
bool operator < (pt b) const {
if (x == b.x) {
return y < b.y;
}
return x < b.x;
}
};
int quad(pt a)
{
static const int q[][2] = {{0, 1}, {3, 2}};
return q[a.x < 0][a.y < 0];
}
int ccw(pt a, pt b, pt c)
{
ll r = (b - a) ^ (c - b);
return (r > 0) - (r < 0);
}
bool polar_cmp(pt a, pt b)
{
if (quad(a) != quad(b)) {
return quad(a) < quad(b);
}
return ccw(pt(0, 0), a, b) < 0;
}
ll dot(pt a, pt b, pt c)
{
return (b - a) * (c - a);
}
void pre()
{
}
#define TEST 0
void solve()
{
int n, q;
cin >> n >> q;
V<pt> a(n + q);
cin >> a;
vl ans(q);
vi p(n + q);
iota(all(p), 0);
rep(i, n + q) {
sort(all(p), [&](int j, int k){
return polar_cmp(a[j] - a[i], a[k] - a[i]);
});
int j = 0;
int now = 1;
while (j < n + q) {
int p1 = p[j];
int p2 = p[now];
if (p1 == i) {
j++;
continue;
}
if (now == j || p2 == i) {
now = (now + 1) % (q + n);
continue;
}
if (ccw(a[i], a[p1], a[p2]) >= 0) {
j++;
continue;
}
ll d = dot(a[i], a[p1], a[p2]);
if (d < 0) {
j++;
continue;
}
if (d > 0) {
now = (now + 1) % (q + n);
continue;
}
if (i >= n && p1 < n && p2 < n) {
ans[i - n]++;
} else if (i < n && p1 >= n && p2 < n) {
ans[p1 - n]++;
} else if (i < n && p1 < n && p2 >= n) {
ans[p2 - n]++;
}
j++;
}
}
repv(i, ans) {
cout << i << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,95 @@
/* Problem URL: https://codeforces.com/gym/102346/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
n--;
int carlos;
cin >> carlos;
while (n--) {
int nm;
cin >> nm;
if (nm > carlos) {
cout << "N\n";
return 0;
}
}
cout << "S\n";
}

View File

@@ -0,0 +1,129 @@
/* Problem URL: https://codeforces.com/gym/102346/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vvi graph(n);
nrep(i, 1, n) {
int p;
cin >> p;
graph[p - 1].push_back(i);
}
V<multiset<int, greater<>>> sets(n);
function<void(int)> dfs = [&](int i) {
for (auto j : graph[i]) {
dfs(j);
if (sets[j].size() > sets[i].size()) {
swap(sets[j], sets[i]);
}
for (auto k : sets[j]) {
sets[i].insert(k);
}
}
if (sets[i].empty()) {
sets[i].insert(1);
return;
}
auto itr = sets[i].begin();
int v = *itr + 1;
sets[i].erase(itr);
sets[i].insert(v);
};
dfs(0);
int ans = 0;
auto itr = sets[0].begin();
rep(i, k) {
if (itr == sets[0].end()) {
break;
}
ans += *itr;
itr++;
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,91 @@
/* Problem URL: https://codeforces.com/gym/102346/problem/H */
#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, v;
cin >> n >> v;
v *= n;
cout << (ll)ceil(v * 0.1) << ' ';
cout << (ll)ceil(v * 0.2) << ' ';
cout << (ll)ceil(v * 0.3) << ' ';
cout << (ll)ceil(v * 0.4) << ' ';
cout << (ll)ceil(v * 0.5) << ' ';
cout << (ll)ceil(v * 0.6) << ' ';
cout << (ll)ceil(v * 0.7) << ' ';
cout << (ll)ceil(v * 0.8) << ' ';
cout << (ll)ceil(v * 0.9) << '\n';
}

View File

@@ -0,0 +1,204 @@
/* Problem URL: https://codeforces.com/gym/102346/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 (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, k;
cin >> n >> k;
vvi cards(n, vi(14, 0));
map<char, int> act;
act['A'] = 1;
act['2'] = 2;
act['3'] = 3;
act['4'] = 4;
act['5'] = 5;
act['6'] = 6;
act['7'] = 7;
act['8'] = 8;
act['9'] = 9;
act['D'] = 10;
act['Q'] = 11;
act['J'] = 12;
act['K'] = 13;
rep(i, n) {
string a;
cin >> a;
repv(j, a) {
cards[i][act[j]]++;
}
}
k--;
rep(i, n) {
if (i == k) {
continue;
}
nrep(j, 1, 14) {
if (cards[i][j] == 4) {
cout << i + 1 << '\n';
return 0;
}
}
}
rep(i, n) {
int minimal = 2;
int choice = 13;
int now = (i + k) % n;
for (int j = 13; j > 0; j--) {
if (cards[now][j] <= minimal && cards[now][j] > 0) {
minimal = cards[now][j];
choice = j;
}
}
cards[now][choice]--;
cards[(now + 1) % n][choice]++;
if (now != k) {
nrep(j, 1, 14) {
if (cards[now][j] == 4) {
rep(l, n) {
nrep(c, 1, 14) {
if (cards[l][c] == 4 && l != k) {
cout << l + 1 << '\n';
return 0;
}
}
}
}
}
}
}
nrep(i, 1, 14) {
if (cards[k][i] == 4) {
cout << k + 1 << '\n';
return 0;
}
}
k = (k + 1) % n;
while (true) {
rep(i, n - 1) {
int minimal = 2;
int choice = 13;
int now = (k + i) % n;
for (int j = 13; j > 0; j--) {
if (cards[now][j] <= minimal && cards[now][j] > 0) {
minimal = cards[now][j];
choice = j;
}
}
cards[now][choice]--;
cards[(now + 1) % n][choice]++;
if (now != ((k - 1) % n + n) % n) {
nrep(j, 1, 14) {
if (cards[now][j] == 4) {
rep(l, n) {
nrep(c, 1, 14) {
if (cards[l][c] == 4 && l != ((k - 1) % n + n) % n) {
cout << l + 1 << '\n';
return 0;
}
}
}
}
}
}
}
nrep(i, 1, 14) {
if (cards[k][i] == 4) {
cout << k + 1 << '\n';
return 0;
}
}
k = (k + 1) % n;
}
}

View File

@@ -0,0 +1,80 @@
/* Problem URL: https://codeforces.com/gym/102346/problem/L */
#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);
ll n;
cin >> n;
cout << (1LL << (__builtin_popcountll(n))) << '\n';
}

View File

@@ -0,0 +1,125 @@
/* Problem URL: https://codeforces.com/gym/102346/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 (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, c, t;
cin >> n >> c >> t;
vi pop(n);
repv(i, pop) {
cin >> i;
// i = (i + (t - 1)) / t;
}
ll ans = 1;
ll low = 1;
ll high = 1e9;
while (low <= high) {
ll mid = (low + high) / 2;
int count = 1;
ll now = 0;
rep(i, n) {
if ((pop[i] + (t - 1)) / t > mid) {
now = 1e9 + 1;
break;
}
now += pop[i];
if ((now + (t - 1)) / t > mid) {
if (count == c) {
break;
}
count++;
now = pop[i];
}
}
if ((now + (t - 1)) / t <= mid) {
ans = mid;
high = mid - 1;
continue;
}
low = mid + 1;
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,117 @@
/* Problem URL: https://codeforces.com/gym/102861/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
V<V<bool>> pos(10, V<bool>(10));
while (n--) {
int d, l, r, c;
cin >> d >> l >> r >> c;
r--, c--;
if (d == 0) {
if (c + l - 1 > 9) {
cout << "N\n";
return 0;
}
nrep(i, c, c + l) {
if (pos[r][i]) {
cout << "N\n";
return 0;
}
pos[r][i] = true;
}
} else {
if (r + l - 1 > 9) {
cout << "N\n";
return 0;
}
nrep(i, r, r + l) {
if (pos[i][c]) {
cout << "N\n";
return 0;
}
pos[i][c] = true;
}
}
}
cout << "Y\n";
}

View File

@@ -0,0 +1,189 @@
/* Problem URL: https://codeforces.com/gym/102861/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);
int n, m;
cin >> n >> m;
vvi graph(n);
vi age(n);
rep(i, n) {
cin >> age[i];
int j;
cin >> j;
if (i == 0) {
continue;
}
graph[j - 1].push_back(i);
}
const int log = 17;
vvi parent(n, vi(log));
vvi maximal(n, vi(log));
function<void(int, int)> dfs = [&](int i, int p) {
parent[i][0] = p;
maximal[i][0] = age[p];
nrep(j, 1, log) {
parent[i][j] = parent[parent[i][j - 1]][j - 1];
maximal[i][j] = max(age[parent[i][j]], maximal[i][j - 1]);
}
for (auto j : graph[i]) {
dfs(j, i);
}
};
dfs(0, 0);
vvi count(n);
while (m--) {
int i, l, r;
cin >> i >> l >> r;
i--;
auto add = [&]() {
for (int j = log - 1; j >= 0; j--) {
if (maximal[i][j] <= r) {
i = parent[i][j];
}
}
count[i].push_back(l);
};
add();
}
int size = 1 << (32 - __builtin_clz(1e5));
vi seg(size * 2);
auto update = [&](int i, int v) {
i += size;
seg[i] += v;
for (i >>= 1; i > 0; i >>= 1) {
seg[i] = seg[i * 2] + seg[i * 2 + 1];
}
};
function<int(int, int, int, int, int)> query = [&](int i, int l, int r, int tl, int tr) {
if (l > tr || r < tl) {
return 0;
}
if (l >= tl && r <= tr) {
return seg[i];
}
int mid = (l + r) >> 1;
return query(i * 2, l, mid, tl, tr) + query(i * 2 + 1, mid + 1, r, tl, tr);
};
vi ans(n);
function<void(int)> getans = [&](int i) {
repv(j, count[i]) {
update(j, 1);
}
ans[i] = query(1, 0, size - 1, 0, age[i]);
for (auto j : graph[i]) {
getans(j);
}
repv(j, count[i]) {
update(j, -1);
}
};
getans(0);
cout << ans << '\n';
}

View File

@@ -0,0 +1,122 @@
/* Problem URL: https://codeforces.com/gym/102861/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string a;
cin >> a;
vi points(2);
vi games(2);
int now = 0;
const char *msg[] = {
"",
"",
"(winner)"
};
const char *left[] = {
"*",
""
};
const char *right[] = {
"",
"*"
};
repv(i, a) {
if (i == 'S') {
points[now]++;
} else if (i == 'R') {
now ^= 1;
points[now]++;
} else if (i == 'Q') {
if (games[0] == 2 || games[1] == 2) {
printf("%d %s - %d %s\n", games[0], msg[games[0]], games[1], msg[games[1]]);
continue;
}
printf("%d (%d%s) - %d (%d%s)\n", games[0], points[0], left[now], games[1], points[1], right[now]);
}
if (points[now] == 10 || (points[now] >= 5 && points[now] - points[now^1] >= 2)) {
games[now]++;
points[0] = 0;
points[1] = 0;
}
}
}

View File

@@ -0,0 +1,96 @@
/* Problem URL: https://codeforces.com/gym/102861/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);
cin >> fds;
vi pref(n + 1);
pref[0] = 100;
rep(i, n) {
pref[i + 1] = pref[i] + fds[i];
}
int maximal = 0;
repv(i, pref) {
rmax(maximal, i);
}
cout << maximal << '\n';
}

View File

@@ -0,0 +1,125 @@
/* Problem URL: https://codeforces.com/gym/103388/problem/C */
#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);
ll b;
int l;
cin >> b >> l;
ll mod = b + 1;
auto fastpow = [&](ll a, ll p) {
ll ans = 1;
ll now = a;
rep(i, 20) {
if ((p >> i) & 1) {
ans *= now;
ans %= mod;
}
now *= now;
now %= mod;
}
return ans;
};
vl fds(l);
cin >> fds;
ll now = 0;
rep(i, l) {
now += fds[i] * fastpow(b, l - i - 1);
now %= mod;
}
if (now == 0) {
cout << "0 0\n";
return 0;
}
rep(i, l) {
ll p = fastpow(b, l - i - 1);
ll tmp = (p * now) % mod;
if (fds[i] >= tmp) {
cout << i + 1 << ' ' << fds[i] - tmp << '\n';
return 0;
}
}
cout << "-1 -1\n";
}

View File

@@ -0,0 +1,128 @@
/* Problem URL: https://codeforces.com/gym/103388/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int now = 0;
int dir = 0;
now = 0;
dir = 0;
V<queue<int>> fds(2);
while (n--) {
int t, d;
cin >> t >> d;
fds[d].push(t);
}
while (!fds[0].empty() || !fds[1].empty()) {
if (fds[0].empty()) {
dir = 1;
} else if (fds[1].empty()) {
dir = 0;
} else {
dir = fds[0].front() > fds[1].front();
}
if (fds[dir].front() <= now) {
while (!fds[dir].empty() && fds[dir].front() <= now) {
fds[dir].pop();
}
now += 10;
while (!fds[dir].empty() && fds[dir].front() <= now) {
now = fds[dir].front() + 10;
fds[dir].pop();
}
continue;
}
now = fds[dir].front() + 10;
fds[dir].pop();
while (!fds[dir].empty() && fds[dir].front() <= now) {
now = fds[dir].front() + 10;
fds[dir].pop();
}
}
cout << now << '\n';
}

View File

@@ -0,0 +1,133 @@
/* Problem URL: https://codeforces.com/gym/103388/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);
ll n;
cin >> n;
vl dp(77);
dp[0] = 1;
dp[1] = 1;
rep(i, 75) {
dp[i + 1] += dp[i];
dp[i + 2] += dp[i];
}
unordered_map<ll, bool> vis;
vi ans;
function<bool(ll)> dfs = [&](ll now) {
if (now == 1) {
return true;
}
if (vis[now]) {
return false;
}
vis[now] = true;
for (int i = 74; i > 0; i--) {
if (now % dp[i] == 0) {
bool res = dfs(now / dp[i]);
if (res) {
ans.push_back(i);
return true;
}
}
}
return false;
};
if (!dfs(n)) {
cout << "IMPOSSIBLE\n";
return 0;
}
reverse(all(ans));
string tmp;
repv(i, ans) {
tmp += string(i, 'A');
tmp += 'B';
}
cout << tmp << '\n';
}

View File

@@ -0,0 +1,111 @@
/* Problem URL: https://codeforces.com/gym/103388/problem/H */
#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, k;
cin >> n >> k;
vvi blocks(k);
vi act;
while (n--) {
int num, c;
cin >> num >> c;
blocks[c - 1].push_back(num);
act.push_back(c - 1);
}
rep(i, k) {
sort(all(blocks[i]), greater<>());
}
vi ans;
rep(i, act.size()) {
ans.push_back(blocks[act[i]].back());
blocks[act[i]].pop_back();
}
nrep(i, 1, ans.size()) {
if (ans[i - 1] > ans[i]) {
cout << "N\n";
return 0;
}
}
cout << "Y\n";
}

View File

@@ -0,0 +1,100 @@
/* Problem URL: https://codeforces.com/gym/103388/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 (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 t, d, m;
cin >> t >> d >> m;
int prev = 0;
while (m--) {
int n;
cin >> n;
if (n - prev >= t) {
cout << "Y\n";
return 0;
}
prev = n;
}
if (d - prev >= t) {
cout << "Y\n";
return 0;
}
cout << "N\n";
}

View File

@@ -0,0 +1,130 @@
/* Problem URL: https://codeforces.com/gym/103388/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 (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 q;
cin >> q;
vvi graph(1);
int cur = 1;
vi status(1);
vi chosen(1);
vi parent(1);
function<int(int)> dfs = [&](int i) {
if (status[i] != -1) {
return i;
}
while (chosen[i] < graph[i].size()) {
int res = dfs(graph[i][chosen[i]]);
if (res == -1) {
chosen[i]++;
continue;
}
return res;
}
return -1;
};
while (q--) {
int p, c;
cin >> p >> c;
if (p == 1) {
graph[c - 1].push_back(graph.size());
graph.emplace_back();
parent.push_back(c - 1);
status.push_back(0);
chosen.push_back(0);
continue;
}
status[c - 1] = -1;
int ans = cur - 1;
int tmp;
while ((tmp = dfs(ans)) == -1) {
ans = parent[ans];
}
cur = tmp + 1;
cout << cur << '\n';
}
}

View File

@@ -0,0 +1,132 @@
/* Problem URL: https://codeforces.com/gym/103388/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 (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 y, n;
cin >> y >> n;
vi fds(y);
cin >> fds;
while (__builtin_popcount(y) != 1) {
y++;
fds.push_back(0);
}
vvi seg(y * 2);
function<void(int, int, int)> build = [&](int i, int l, int r) {
if (l == r) {
seg[i].push_back(fds[i - y]);
return;
}
int mid = (l + r) / 2;
build(i * 2, l, mid);
build(i * 2 + 1, mid + 1, r);
merge(all(seg[i * 2]), all(seg[i * 2 + 1]), back_inserter(seg[i]));
};
build(1, 0, y - 1);
function<int(int, int, int, int, int, int)> query = [&](int i, int l, int r, int tl, int tr, int v) -> int {
if (l > tr || r < tl) {
return 0;
}
if (l >= tl && r <= tr) {
auto lower = lower_bound(all(seg[i]), v);
return seg[i].end() - lower;
}
int mid = (l + r) / 2;
return query(i * 2, l, mid, tl, tr, v) + query(i * 2 + 1, mid + 1, r, tl, tr, v);
};
while (n--) {
int a, p ,f;
cin >> a >> p >> f;
if (fds[a - 1] >= p) {
cout << "0\n";
continue;
}
cout << query(1, 0, y - 1, a - 1, a + f - 1, p) << '\n';
}
}

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';
}

View File

@@ -0,0 +1,211 @@
/* Problem URL: https://codeforces.com/gym/104020/problem/L?mobile=false */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
struct point {
ll x;
ll y;
ll z;
friend istream &operator>>(istream &is, point &a) {
is >> a.x >> a.y >> a.z;
return is;
}
bool operator<(point b) const {
if (x == b.x) {
if (y == b.y) {
return z < b.z;
}
return y < b.y;
}
return x < b.x;
}
};
ll sqr(ll x)
{
return x * x;
}
long double dis(point a, point b)
{
ll x = a.x - b.x;
ll y = a.y - b.y;
ll z = a.z - b.z;
return sqrtl(sqr(x) + sqr(y) + sqr(z));
}
void solve()
{
int n;
cin >> n;
V<point> p(n);
cin >> p;
sortv(p);
long double ans = 1e16;
struct compy {
bool operator()(point a, point b) const {
if (a.y == b.y) {
if (a.z == b.z) {
return a.x > b.x;
}
return a.z > b.z;
}
return a.y > b.y;
}
};
struct compz {
bool operator()(point a, point b) const {
if (a.z == b.z) {
if (a.x == b.x) {
return a.y > b.y;
}
return a.x > b.x;
}
return a.z > b.z;
}
};
set<point, compy> sy;
set<point, compz> sz;
sy.emplace(p[0]);
sz.emplace(p[0]);
int cur = 0;
nrep(i, 1, n) {
while (p[cur].x < p[i].x - ans) {
sy.erase(p[cur]);
sz.erase(p[cur]);
cur++;
}
auto itr = sy.lower_bound(point(1e9, p[i].y + ans, 1e9));
while (itr != sy.end() && abs(p[i].y - itr->y) <= ans) {
rmin(ans, dis(p[i], *itr));
itr++;
}
itr = sz.lower_bound(point(1e9, 1e9, p[i].z + ans));
while (itr != sz.end() && abs(p[i].z - itr->z) <= ans) {
rmin(ans, dis(p[i], *itr));
itr++;
}
sy.emplace(p[i]);
sz.emplace(p[i]);
}
cout << fixed << setprecision(7) << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,137 @@
/* Problem URL: https://codeforces.com/gym/104114/problem/F */
#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);
int n;
cin >> n;
vvl fds(n, vl(n));
cin >> fds;
V<tuple<ll, int, int>> edges;
rep(i, n) {
nrep(j, i + 1, n) {
edges.emplace_back(fds[i][j], i, j);
}
}
sort(all(edges), greater<>());
vi dsu(n);
rep(i, n) {
dsu[i] = i;
}
function<int(int)> find_p = [&](int i) {
if (dsu[i] == i) {
return i;
}
return dsu[i] = find_p(dsu[i]);
};
auto join = [&](int a, int b) {
a = find_p(a);
b = find_p(b);
if (b < a) {
swap(a, b);
}
dsu[b] = a;
return a != b;
};
ll ans = 0;
V<pair<int, int>> aedg;
for (auto [c, u, v] : edges) {
v = find_p(v);
u = find_p(u);
if (join(u, v)) {
ans += c;
aedg.emplace_back(u, v);
}
}
cout << ans << '\n';
for (auto [u, v] : aedg) {
cout << u + 1 << ' ' << v + 1 << '\n';
}
}

View File

@@ -0,0 +1,162 @@
/* Problem URL: https://codeforces.com/gym/104114/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vl fds(n);
cin >> fds;
vl diffs(n - 1);
rep(i, n - 1) {
diffs[i] = abs(fds[i] - fds[i + 1]);
}
vl ans(n);
nrep(i, 1, n) {
ans[i] = diffs[i - 1] - ans[i - 1];
}
map<ll, int> count;
rep(i, n) {
ll n;
cin >> n;
count[n]++;
}
ll oo = INT64_MAX >> 1;
ll minimal_odd = oo;
ll odd_i = 0;
ll minimal_ev = oo;
ll ev_i = 0;
rep(i, n) {
if (i & 1) {
if (ans[i] < minimal_odd) {
minimal_odd = ans[i];
odd_i = i;
}
continue;
}
if (ans[i] < minimal_ev) {
minimal_ev = ans[i];
ev_i = i;
}
}
auto check_k = [&](ll k) {
rep(i, n) {
ll now = 0;
if (i & 1) {
now = ans[i] - k;
} else {
now = ans[i] + k;
}
if (count[now] == 0) {
return false;
}
count[now]--;
}
return true;
};
ll act = count.begin()->first;
ll k = -(ans[ev_i] - act);
if (!check_k(k)) {
k = ans[odd_i] - act;
}
rep(i, n) {
if (i & 1) {
cout << ans[i] - k;
} else {
cout << ans[i] + k;
}
cout << " \n"[i == n - 1];
}
}

View File

@@ -0,0 +1,196 @@
/* Problem URL: https://codeforces.com/gym/103934/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll c, x, t, n;
cin >> c >> x >> t >> n;
ll t1, t2, t3;
cin >> t1 >> t2 >> t3;
if (c == 1) {
cout << max({t - t1, t - t2, t - t3}) << '\n';
return 0;
}
vl count(3);
vl prev(3);
vl prevadd(3);
vl ti = {t1, t2, t3};
ll ans = 0;
V<pair<ll, ll>> fds(n);
repv(i, fds) {
cin >> i.first >> i.second;
}
sortv(fds);
auto binsearch = [&](ll low, ll high, ll lim) {
ll ans = 0;
while (low <= high) {
ll mid = (high + low) >> 1;
if (x * mid <= lim) {
ans = mid;
low = mid + 1;
continue;
}
high = mid - 1;
}
return ans;
};
auto updateprev = [&](int i, ll time) {
if (time - prev[i] <= x) {
return;
}
if (prev[i] + x + ti[i] > t) {
count[i] = 0;
ll diff = time - prev[i];
ll binans = binsearch(0, diff / x, t - ti[i] - prev[i]);
if (prev[i] + x * binans + ti[i] < t) {
rmax(ans, prev[i] + x * binans);
}
prev[i] += diff / x * x;
return;
}
ll diff = time - prev[i];
ll binans = binsearch(0, diff / x, t - ti[i] - prev[i]);
if (prev[i] + x * binans + ti[i] < t) {
rmax(ans, prev[i] + x * binans);
}
prev[i] += diff / x * x;
count[i] = 0;
return;
};
auto updatetime = [&](int i, ll time) {
if (count[i] < c - 1) {
return;
}
if (count[i] == c) {
if (prevadd[i] + ti[i] <= min(t, time)) {
rmax(ans, min(t, time) - ti[i]);
}
if (time + ti[i] <= t) {
rmax(ans, time);
}
count[i] = 0;
prev[i] = time;
prevadd[i] = time;
return;
}
if (time + ti[i] <= t) {
rmax(ans, time);
}
prevadd[i] = time;
};
repv(i, fds) {
ll time = i.first;
updateprev(0, time);
updateprev(1, time);
updateprev(2, time);
count[i.second - 1]++;
updatetime(0, time);
updatetime(1, time);
updatetime(2, time);
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,96 @@
/* Problem URL: https://codeforces.com/gym/103960/problem/A */
#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;
string a;
cin >> n >> a;
int ans = 0;
int count = 0;
repv(i, a) {
if (i == 'b') {
ans += count >= 2 ? count : 0;
count = 0;
continue;
}
count++;
}
ans += count >= 2 ? count : 0;
cout << ans << '\n';
}

View File

@@ -0,0 +1,108 @@
/* Problem URL: https://codeforces.com/gym/103960/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, is, js;
cin >> n >> is >> js;
int inf = INT32_MAX >> 1;
vi dp(1 << n, inf);
auto bfs = [&]() {
queue<int> q;
dp[1 << (n - 1)] = 0;
q.push(1 << (n - 1));
while (!q.empty()) {
int i = q.front();
q.pop();
if (dp[i >> 1] > dp[i] + 1) {
dp[i >> 1] = dp[i] + 1;
q.push(i >> 1);
}
if (dp[(i + (1 << n)) >> 1] > dp[i] + 1) {
dp[(i + (1 << n)) >> 1] = dp[i] + 1;
q.push((i + (1 << n)) >> 1);
}
}
};
bfs();
cout << dp[is] << '\n';
}

View File

@@ -0,0 +1,99 @@
/* Problem URL: https://codeforces.com/gym/103960/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vi c(1e6 + 1, 0);
int ans = 0;
while (n--) {
int now;
cin >> now;
if (c[now] == 0) {
ans++;
c[now - 1]++;
continue;
}
c[now]--;
c[now - 1]++;
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,150 @@
/* Problem URL: https://codeforces.com/gym/103960/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, c;
cin >> n >> c;
vvi trie(1, vi(26));
vvi count(1, vi(26));
function<int(string&, int, int)> add = [&](string &a, int i, int p) {
if (a[i] == '*') {
int maximal = 0;
rep(j, 26) {
if (trie[p][j] == 0) {
trie[p][j] = trie.size();
trie.emplace_back(26);
count.emplace_back(26);
}
if (i == c - 1) {
count[p][j]++;
rmax(maximal, count[p][j]);
continue;
}
rmax(count[p][j], add(a, i + 1, trie[p][j]));
rmax(maximal, count[p][j]);
}
return maximal;
}
if (trie[p][a[i] - 'a'] == 0) {
trie[p][a[i] - 'a'] = trie.size();
trie.emplace_back(26);
count.emplace_back(26);
}
if (i == c - 1) {
count[p][a[i] - 'a']++;
return count[p][a[i] - 'a'];
}
rmax(count[p][a[i] - 'a'], add(a, i + 1, trie[p][a[i] - 'a']));
return count[p][a[i] - 'a'];
};
while (n--) {
string f;
cin >> f;
add(f, 0, 0);
}
string ans;
int now = 0;
int ansc = 0;
rep(i, c) {
int tmp = 0;
int maximal = 0;
rep(j, 26) {
if (count[now][j] > maximal) {
maximal = count[now][j];
tmp = j;
}
}
ans.push_back(tmp + 'a');
ansc = maximal;
now = trie[now][tmp];
}
cout << ans << ' ' << ansc << '\n';
}

View File

@@ -0,0 +1,185 @@
/* Problem URL: https://codeforces.com/gym/103960/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vvi graph(n);
vvi inv(n);
vvi comp(n);
while (m--) {
int a, b;
cin >> a >> b;
a--, b--;
graph[a].push_back(b);
inv[b].push_back(a);
comp[a].push_back(b);
comp[b].push_back(a);
}
stack<int> preorder;
V<bool> vis(n);
function<void(int)> getpre = [&](int i) {
vis[i] = true;
for (auto j : graph[i]) {
if (vis[j]) {
continue;
}
getpre(j);
}
preorder.push(i);
};
rep(i, n) {
if (vis[i]) {
continue;
}
getpre(i);
}
int g = 0;
fill(all(vis), false);
V<set<int>> condin;
V<set<int>> condout;
vi group(n, -1);
function<void(int)> dfs = [&](int i) {
vis[i] = true;
group[i] = g;
for (auto j : inv[i]) {
if (group[j] != -1 && group[j] != g) {
condin[g].insert(group[j]);
condout[group[j]].insert(g);
continue;
}
if (vis[j]) {
continue;
}
dfs(j);
}
};
while (!preorder.empty()) {
int i = preorder.top();
preorder.pop();
if (vis[i]) {
continue;
}
condin.emplace_back();
condout.emplace_back();
dfs(i);
g++;
}
if (g == 1) {
cout << "0\n";
return 0;
}
int nonein = 0;
int noneout = 0;
rep(i, g) {
if (condin[i].empty()) {
nonein++;
}
if (condout[i].empty()) {
noneout++;
}
}
cout << max(nonein, noneout) << '\n';
}

View File

@@ -0,0 +1,88 @@
/* Problem URL: https://codeforces.com/gym/103960/problem/I */
#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);
rep(i, 9) {
int n;
cin >> n;
if (n == 9) {
cout << "F\n";
return 0;
}
}
cout << "S\n";
}

View File

@@ -0,0 +1,142 @@
/* Problem URL: https://codeforces.com/gym/103960/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 (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;
map<string, int> card;
vi cards(11, 4);
cards[10] = 16;
int john = 0;
int mary = 0;
vi value(14, 0);
nrep(i, 1, 11) {
value[i] = i;
}
value[11] = 10;
value[12] = 10;
value[13] = 10;
int c1, c2;
cin >> c1 >> c2;
cards[value[c1]]--;
cards[value[c2]]--;
john = value[c1] + value[c2];
cin >> c1 >> c2;
cards[value[c1]]--;
cards[value[c2]]--;
mary = value[c1] + value[c2];
while (n--) {
int c;
cin >> c;
cards[value[c]]--;
john += value[c];
mary += value[c];
}
if (mary >= john) {
if (23 - mary > 10 || cards[23 - mary] == 0) {
cout << "-1\n";
return 0;
}
cout << 23 - mary << '\n';
return 0;
}
nrep(i, 1, 11) {
if (mary + i > 23) {
cout << "-1\n";
return 0;
}
if (john + i > 23 && cards[i] > 0) {
cout << i << '\n';
return 0;
}
}
cout << "-1\n";
}

View File

@@ -0,0 +1,139 @@
/* Problem URL: https://codeforces.com/gym/104493/problem/K */
#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);
int n, m;
cin >> n >> m;
vvi count(n, vi(26));
rep(i, n) {
string a;
cin >> a;
repv(j, a) {
count[i][j - 'a']++;
}
}
int q;
cin >> q;
while (q--) {
int a, b;
cin >> a >> b;
a--, b--;
int ans = 0;
vi pos(2);
rep(i, 26) {
int act0 = count[a][i];
int act1 = count[b][i];
if (pos[0] <= pos[1]) {
int diff = pos[1] - pos[0];
if (act0 < diff) {
pos[0] += count[a][i];
pos[1] += count[b][i];
continue;
}
act0 -= diff;
pos[0] += diff;
} else {
int diff = pos[0] - pos[1];
if (act1 < diff) {
pos[0] += count[a][i];
pos[1] += count[b][i];
continue;
}
act1 -= diff;
pos[1] += diff;
}
ans += min(act0, act1);
pos[0] += act0;
pos[1] += act1;
}
cout << ans << '\n';
}
}

View File

@@ -0,0 +1,83 @@
/* Problem URL: https://codeforces.com/gym/104785/problem/A */
#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, w;
cin >> n >> w;
rep(i, n) {
cout << w - i << ' ' << 500 << '\n';
}
}

View File

@@ -0,0 +1,157 @@
/* Problem URL: https://codeforces.com/gym/104785/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;
}
int parent[(ll)2e6 + 1][21];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, c;
cin >> n >> c;
vl fds(n);
cin >> fds;
rep(i, n) {
fds.push_back(fds[i]);
}
vl pref(n * 2 + 1);
rep(i, n * 2) {
pref[i + 1] = pref[i] + fds[i];
}
vvi graph(n * 2 + 1);
rep(i, n * 2) {
int ans = -1;
int low = i;
int high = min((int)i + n - 1, n * 2 - 1);
while (low <= high) {
int mid = (low + high) / 2;
if (pref[mid + 1] - pref[i] >= c) {
ans = mid + 1;
high = mid - 1;
continue;
}
low = mid + 1;
}
if (ans != -1) {
graph[ans].push_back(i);
}
}
int inf = INT32_MAX >> 1;
rep(i, n * 2 + 1) {
rep(j, 21) {
parent[i][j] = inf;
}
}
// vvi parent(n * 2 + 1, vi(21, inf));
V<bool> vis(n * 2 + 1, false);
function<void(int, int)> dfs = [&](int i, int p){
parent[i][0] = p;
vis[i] = true;
for (int j = 1; j <= 20 && parent[i][j - 1] != inf; j++) {
parent[i][j] = parent[parent[i][j - 1]][j - 1];
}
for (auto j : graph[i]) {
dfs(j, i);
}
};
for (int i = n * 2; i >= 0; i--) {
if (!vis[i]) {
dfs(i, inf);
}
}
rep(i, n) {
int now = i;
int ans = 0;
for (int j = 20; j >= 0; j--) {
if (parent[now][j] < i + n) {
ans += (1 << j);
now = parent[now][j];
}
}
cout << ans << ' ';
}
cout << '\n';
}

View File

@@ -0,0 +1,108 @@
/* Problem URL: https://codeforces.com/gym/104785/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;
vi dec;
vi cres;
rep(i, m) {
int a, b;
cin >> a >> b;
if (a > b) {
dec.push_back(i + 1);
} else {
cres.push_back(i + 1);
}
}
cout << "YES\n";
if (dec.size() > cres.size()) {
cout << dec.size() << '\n';
for (auto i : dec) {
cout << i << ' ';
}
cout << '\n';
return 0;
}
cout << cres.size() << '\n';
for (auto i : cres) {
cout << i << ' ';
}
cout << '\n';
}

View File

@@ -0,0 +1,116 @@
/* Problem URL: https://codeforces.com/gym/104785/problem/L */
#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 h1, d1, t1;
cin >> h1 >> d1 >> t1;
ll h2, d2, t2;
cin >> h2 >> d2 >> t2;
h1 -= d2;
h2 -= d1;
if (h1 < 0 && h2 < 0) {
cout << "draw\n";
return 0;
}
if (h1 < 0) {
cout << "player two\n";
return 0;
}
if (h2 < 0) {
cout << "player one\n";
return 0;
}
ll killt1 = (h1 / d2 + min(1LL, h1 % d2)) * t2;
ll killt2 = (h2 / d1 + min(1LL, h2 % d1)) * t1;
if (killt1 == killt2) {
cout << "draw\n";
return 0;
}
if (killt1 > killt2) {
cout << "player one\n";
return 0;
}
if (killt2 > killt1) {
cout << "player two\n";
}
}

View File

@@ -0,0 +1,91 @@
/* Problem URL: https://codeforces.com/gym/104785/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 a, b, c;
cin >> a >> b >> c;
int squares = 2 * a;
int ret = 0;
if (c > 1 && b >= 1) {
c -= 2;
ret += 2 + b * 2;
ret++;
}
ret += 3 * (c / 2);
cout << squares + ret << '\n';
}

View File

@@ -0,0 +1,131 @@
/* Problem URL: https://codeforces.com/gym/104785/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 n;
cin >> n;
map<string, string> var;
var["0.75"] = "standard";
var["15"] = "nebuchadnezzar";
var["12"] = "balthazar";
string now = "a";
while (n--) {
string a;
cin >> a;
size_t i = 0;
string b;
while (a[i] != 'L' && a[i] == '0') {
i++;
}
if (a[i] == 'L') {
b = "0";
} else {
while (a[i] != '.' && a[i] != 'L') {
b.push_back(a[i]);
i++;
}
if (a[i] != 'L') {
i++;
string tmp;
while (a[i] != 'L') {
while (a[i] == '0') {
tmp.push_back(a[i]);
i++;
}
if (a[i] != 'L') {
b += tmp;
b += a[i];
i++;
}
}
}
}
auto itr = var.find(b);
if (itr == var.end()) {
var[b] = now;
now += 'a';
}
cout << var[b] << '\n';
}
}

View File

@@ -0,0 +1,153 @@
/* Problem URL: https://codeforces.com/gym/104736/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 (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;
vvi graph(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vi ans(n);
int prev = n - 1;
if (n > 1) {
n = 1 << (32 - __builtin_clz(n - 1));
}
int inf = INT32_MAX >> 1;
vi seg(n * 2, inf);
auto update = [&](int i, int v) {
seg[i + n] = v;
for (int j = (i + n) / 2; j > 0; j /= 2) {
seg[j] = min(seg[j * 2], seg[j * 2 + 1]);
}
};
function<int(int, int, int, int, int)> search = [&](int i, int l, int r, int tl, int tr) {
if (l > tr || r < tl || seg[i] == inf) {
return -1;
}
if (l == r) {
return i - n;
}
if (l >= tl && r <= tr) {
int mid = (l + r) / 2;
if (seg[i * 2] <= seg[i * 2 + 1]) {
return search(i * 2, l, mid, tl, tr);
}
return search(i * 2 + 1, mid + 1, r, tl, tr);
}
int mid = (l + r) / 2;
int ans1 = search(i * 2, l, mid, tl, tr);
int ans2 = search(i * 2 + 1, mid + 1, r, tl, tr);
if (ans2 == -1 || seg[ans1 + n] < seg[ans2 + n] || (seg[ans1 + n] == seg[ans2 + n] && ans1 < ans2)) {
return ans1;
}
return ans2;
};
function<void(int, int, int)> dfs = [&](int i, int p, int d) {
update(i, d);
ans[i] = search(1, 0, n - 1, i, n - 1) + 1;
for (auto j : graph[i]) {
if (j == p) {
continue;
}
dfs(j, i, d - 1);
}
update(i, inf);
};
dfs(prev, -1, inf - 1);
cout << ans;
}

View File

@@ -0,0 +1,91 @@
/* Problem URL: https://codeforces.com/gym/104555/problem/A */
#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, h;
cin >> n >> h;
int ans = 0;
while (n--) {
int num;
cin >> num;
if (h >= num) {
ans++;
}
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,109 @@
/* Problem URL: https://codeforces.com/gym/104555/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, k;
cin >> n >> k;
vi count(1e6 + 1);
count[0] = 1e9;
while (n--) {
int num;
cin >> num;
count[num]++;
}
auto calc = [&](int i) {
int tmp = i;
int sum = 0;
while (tmp > 0) {
sum += tmp % 10;
tmp /= 10;
}
return sum;
};
int ans = 1e6;
while (count[ans] < k) {
k -= count[ans];
count[ans - calc(ans)] += count[ans];
ans--;
}
cout << calc(ans) << '\n';
}

View File

@@ -0,0 +1,101 @@
/* Problem URL: https://codeforces.com/gym/104555/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int d, c, r;
cin >> d >> c >> r;
int ans = r;
vi fds(c);
cin >> fds;
while (r--) {
int num;
cin >> num;
d += num;
}
rep(i, fds.size()) {
if (d >= fds[i]) {
d -= fds[i];
ans++;
} else {
break;
}
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,314 @@
/* Problem URL: https://codeforces.com/gym/104555/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>;
#define sq(x) ((x)*(ll)(x))
struct pt { // ponto
int x, y;
pt(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
bool operator < (const pt p) const {
if (x != p.x) return x < p.x;
return y < p.y;
}
bool operator == (const pt p) const {
return x == p.x and y == p.y;
}
pt operator + (const pt p) const { return pt(x+p.x, y+p.y); }
pt operator - (const pt p) const { return pt(x-p.x, y-p.y); }
pt operator * (const int c) const { return pt(x*c, y*c); }
ll operator * (const pt p) const { return x*(ll)p.x + y*(ll)p.y; }
ll operator ^ (const pt p) const { return x*(ll)p.y - y*(ll)p.x; }
friend istream& operator >> (istream& in, pt& p) {
return in >> p.x >> p.y;
}
};
struct line { // reta
pt p, q;
line() {}
line(pt p_, pt q_) : p(p_), q(q_) {}
friend istream& operator >> (istream& in, line& r) {
return in >> r.p >> r.q;
}
};
// PONTO & VETOR
ll dist2(pt p, pt q) { // quadrado da distancia
return sq(p.x - q.x) + sq(p.y - q.y);
}
ll sarea2(pt p, pt q, pt r) { // 2 * area com sinal
return (q-p)^(r-q);
}
bool col(pt p, pt q, pt r) { // se p, q e r sao colin.
return sarea2(p, q, r) == 0;
}
bool ccw(pt p, pt q, pt r) { // se p, q, r sao ccw
return sarea2(p, q, r) > 0;
}
int quad(pt p) { // quadrante de um ponto
return (p.x<0)^3*(p.y<0);
}
bool compare_angle(pt p, pt q) { // retorna se ang(p) < ang(q)
if (quad(p) != quad(q)) return quad(p) < quad(q);
return ccw(q, pt(0, 0), p);
}
pt rotate90(pt p) { // rotaciona 90 graus
return pt(-p.y, p.x);
}
// RETA
bool isinseg(pt p, line r) { // se p pertence ao seg de r
pt a = r.p - p, b = r.q - p;
return (a ^ b) == 0 and (a * b) <= 0;
}
bool interseg(line r, line s) { // se o seg de r intersecta o seg de s
if (isinseg(r.p, s) or isinseg(r.q, s)
or isinseg(s.p, r) or isinseg(s.q, r)) return 1;
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);
}
int segpoints(line r) { // numero de pontos inteiros no segmento
return 1 + __gcd(abs(r.p.x - r.q.x), abs(r.p.y - r.q.y));
}
double get_t(pt v, line r) { // retorna t tal que t*v pertence a reta r
return (r.p^r.q) / (double) ((r.p-r.q)^v);
}
// POLIGONO
// quadrado da distancia entre os retangulos a e b (lados paralelos aos eixos)
// assume que ta representado (inferior esquerdo, superior direito)
ll dist2_rect(pair<pt, pt> a, pair<pt, pt> b) {
int hor = 0, vert = 0;
if (a.second.x < b.first.x) hor = b.first.x - a.second.x;
else if (b.second.x < a.first.x) hor = a.first.x - b.second.x;
if (a.second.y < b.first.y) vert = b.first.y - a.second.y;
else if (b.second.y < a.first.y) vert = a.first.y - b.second.y;
return sq(hor) + sq(vert);
}
ll polarea2(vector<pt> v) { // 2 * area do poligono
ll ret = 0;
for (int i = 0; i < v.size(); i++)
ret += sarea2(pt(0, 0), v[i], v[(i + 1) % v.size()]);
return abs(ret);
}
// se o ponto ta dentro do poligono: retorna 0 se ta fora,
// 1 se ta no interior e 2 se ta na borda
int inpol(vector<pt>& v, pt p) { // O(n)
int qt = 0;
for (int i = 0; i < v.size(); i++) {
if (p == v[i]) return 2;
int j = (i+1)%v.size();
if (p.y == v[i].y and p.y == v[j].y) {
if ((v[i]-p)*(v[j]-p) <= 0) return 2;
continue;
}
bool baixo = v[i].y < p.y;
if (baixo == (v[j].y < p.y)) continue;
auto t = (p-v[i])^(v[j]-v[i]);
if (!t) return 2;
if (baixo == (t > 0)) qt += baixo ? 1 : -1;
}
return qt != 0;
}
vector<pt> convex_hull(vector<pt> v) { // convex hull - O(n log(n))
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
if (v.size() <= 1) return v;
vector<pt> l, u;
for (int i = 0; i < v.size(); i++) {
while (l.size() > 1 and !ccw(l.end()[-2], l.end()[-1], v[i]))
l.pop_back();
l.push_back(v[i]);
}
for (int i = v.size() - 1; i >= 0; i--) {
while (u.size() > 1 and !ccw(u.end()[-2], u.end()[-1], v[i]))
u.pop_back();
u.push_back(v[i]);
}
l.pop_back(); u.pop_back();
for (pt i : u) l.push_back(i);
return l;
}
ll interior_points(vector<pt> v) { // pontos inteiros dentro de um poligono simples
ll b = 0;
for (int i = 0; i < v.size(); i++)
b += segpoints(line(v[i], v[(i+1)%v.size()])) - 1;
return (polarea2(v) - b) / 2 + 1;
}
struct convex_pol {
vector<pt> pol;
// nao pode ter ponto colinear no convex hull
convex_pol() {}
convex_pol(vector<pt> v) : pol(convex_hull(v)) {}
// se o ponto ta dentro do hull - O(log(n))
bool is_inside(pt p) {
if (pol.size() == 0) return false;
if (pol.size() == 1) return p == pol[0];
int l = 1, r = pol.size();
while (l < r) {
int m = (l+r)/2;
if (ccw(p, pol[0], pol[m])) l = m+1;
else r = m;
}
if (l == 1) return isinseg(p, line(pol[0], pol[1]));
if (l == pol.size()) return false;
return !ccw(p, pol[l], pol[l-1]);
}
// ponto extremo em relacao a cmp(p, q) = p mais extremo q
// (copiado de https://github.com/gustavoM32/caderno-zika)
int extreme(const function<bool(pt, pt)>& cmp) {
int n = pol.size();
auto extr = [&](int i, bool& cur_dir) {
cur_dir = cmp(pol[(i+1)%n], pol[i]);
return !cur_dir and !cmp(pol[(i+n-1)%n], pol[i]);
};
bool last_dir, cur_dir;
if (extr(0, last_dir)) return 0;
int l = 0, r = n;
while (l+1 < r) {
int m = (l+r)/2;
if (extr(m, cur_dir)) return m;
bool rel_dir = cmp(pol[m], pol[l]);
if ((!last_dir and cur_dir) or
(last_dir == cur_dir and rel_dir == cur_dir)) {
l = m;
last_dir = cur_dir;
} else r = m;
}
return l;
}
int max_dot(pt v) {
return extreme([&](pt p, pt q) { return p*v > q*v; });
}
pair<int, int> tangents(pt p) {
auto L = [&](pt q, pt r) { return ccw(p, r, q); };
auto R = [&](pt q, pt r) { return ccw(p, q, r); };
return {extreme(L), extreme(R)};
}
};
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;
map<pt, int> var;
V<pt> points(n);
rep(i, n) {
cin >> points[i].x >> points[i].y;
var[{points[i].x, points[i].y}] = i + 1;
}
convex_pol conv(points);
set<int> ans;
repv(i, points) {
if (inpol(conv.pol, i) == 2) {
ans.insert(var[i]);
}
}
repv(i, ans) {
cout << i << ' ';
}
cout << '\n';
}

View File

@@ -0,0 +1,114 @@
/* Problem URL: https://codeforces.com/gym/104555/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll s;
cin >> n >> s;
V<tuple<ll, ll, ll>> fds(n);
for (auto &[l, r, c] : fds) {
cin >> l >> r >> c;
}
sortv(fds);
ll ans = 0;
ll cost = 0;
ll ln = 0;
ll rn = 0;
for (auto [l, r, c] : fds) {
ll tmp = (r - l + 1) * s - c;
if (rn < l) {
if (tmp > 0) {
cost = c;
ln = l;
rn = r;
ans += tmp;
}
continue;
}
}
}

View File

@@ -0,0 +1,113 @@
/* Problem URL: https://codeforces.com/gym/104555/problem/I */
#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);
int n;
cin >> n;
vi fds(n);
cin >> fds;
vvl dp(n, vl(2, 0));
dp[0][1] = fds[0];
dp[0][0] = fds[0] ^ 1;
nrep(i, 1, n) {
// if (fds[i] == 0) {
// dp[i][0] = dp[i - 1][0] + 1;
// dp[i][1] = dp[i - 1][1];
// continue;
// }
//
// dp[i][0] = dp[i - 1][1];
// dp[i][1] = dp[i - 1][0] + 1;
dp[i][0] = dp[i - 1][fds[i]] + (fds[i] ^ 1);
dp[i][1] = dp[i - 1][fds[i] ^ 1] + fds[i];
}
ll ans = 0;
rep(i, n) {
ans += dp[i][1];
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,97 @@
/* Problem URL: https://codeforces.com/gym/104555/problem/L */
#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);
string a;
int k;
cin >> a >> k;
V<string> fds(k);
rep(i, a.size()) {
fds[i % k].push_back(a[i]);
}
rep(i, k) {
sort(all(fds[i]), greater<>());
}
rep(i, a.size()) {
cout << fds[i % k].back();
fds[i % k].pop_back();
}
cout << '\n';
}

View File

@@ -0,0 +1,121 @@
/* Problem URL: https://codeforces.com/gym/104555/problem/M */
#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);
int n;
cin >> n;
vvl dis(n, vl(n));
cin >> dis;
vvl tmp = dis;
ll ans = 0;
rep(k, n) {
rep(i, n) {
rep(j, n) {
rmin(tmp[i][j], tmp[i][k] + tmp[k][j]);
}
}
}
if (tmp != dis) {
cout << "-1\n";
return 0;
}
ll oo = INT64_MAX >> 1;
rep(k, n) {
rep(i, n) {
rep(j, n) {
if (i != j && j != k && k != i && dis[i][j] == dis[i][k] + dis[k][j]) {
dis[i][j] = oo;
dis[j][i] = oo;
ans++;
}
}
}
}
cout << ans << '\n';
}

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';
}
}

View File

@@ -0,0 +1,193 @@
/* Problem URL: https://codeforces.com/gym/105231/problem/I */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC target("bmi,bmi2,popcnt,lzcnt")
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;
}
using pd = pair<double, double>;
pd operator+(pd a, pd b) {
pd fds = {a.first + b.first, a.second + b.second};
return fds;
}
pd operator-(pd a, pd b) {
pd fds = {a.first - b.first, a.second - b.second};
return fds;
}
pd operator/(pd a, double f) {
return make_pair(a.first / f, a.second / f);
}
pd operator*(pd a, double f) {
return make_pair(a.first * f, a.second * f);
}
pd rotate90(pd a) {
return pd(-a.second, a.first);
}
double operator^(pd a, pd b) {
return a.first * b.second - a.second * b.first;
}
struct line {
pd p, q;
};
double get_t(pd v, line r) {
return (r.p^r.q) / ((r.p - r.q)^v);
}
double EPS = 1e-6;
double inf = 1e18;
pd inter(line r, line s)
{
if (abs((r.p - r.q) ^ (s.p - s.q)) < EPS) {
return pd(inf, inf);
}
r.q = r.q - r.p, s.p = s.p - r.p, s.q = s.q - r.p;
return (r.q * get_t(r.q, s)) + r.p;
}
pd getcenter(pd a, pd b, pd c) {
b = (a + b) / 2;
c = (a + c) / 2;
return inter(line(b, b + rotate90(a - b)), line(c, c + rotate90(a - c)));
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
V<pair<double, double>> points(n);
repv(i, points) {
cin >> i.first >> i.second;
}
V<double> disses(n, 1e16);
auto dis = [&](pair<double, double> &a, pair<double, double> &b) {
double x = a.first - b.first;
double y = a.second - b.second;
return sqrt(x * x + y * y);
};
V<double> lol(n);
auto calc = [&](pair<double, double> center) {
rep(i, n) {
lol[i] = dis(center, points[i]);
}
};
auto search = [&](pair<double, double> point) {
sortv(lol);
nrep(i, 1, n) {
rmin(disses[i], lol[i]);
}
};
rep(i, n - 1) {
nrep(j, i + 1, n) {
pair<double, double> center = {(points[i].first + points[j].first) / 2, (points[i].second + points[j].second) / 2};
calc(center);
search(center);
}
}
rep(i, n - 2) {
nrep(j, i + 1, n - 1) {
nrep(k, j + 1, n) {
auto center = getcenter(points[i], points[j], points[k]);
calc(center);
search(center);
}
}
}
int act = 1;
nrep(i, 1, n) {
rep(j, act) {
cout << fixed << setprecision(8) << disses[i] << '\n';
}
act++;
}
}

View File

@@ -0,0 +1,231 @@
/* Problem URL: https://codeforces.com/gym/105231/problem/L */
#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, m, k, t;
cin >> n >> m >> k >> t;
vl fds(n);
cin >> fds;
V<tuple<int, int, int>> gates;
rep(i, k) {
int n, l, r;
cin >> n >> l >> r;
n--;
gates.emplace_back(n, l, r);
}
ll inf = INT64_MAX >> 1;
vvl dis(n, vl(k, inf));
V<V<pair<int, ll>>> graph(n);
auto dijkstra = [&](int i, int k) {
priority_queue<pair<ll, int>, V<pair<ll, int>>, greater<>> pq;
dis[i][k] = 0;
pq.emplace(0, i);
while (!pq.empty()) {
auto [c, now] = pq.top();
pq.pop();
if (c > dis[now][k]) {
continue;
}
for (auto [j, cost] : graph[now]) {
if (dis[j][k] > cost + c) {
dis[j][k] = cost + c;
pq.emplace(cost + c, j);
}
}
}
};
while (m--) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
graph[a].emplace_back(b, c);
graph[b].emplace_back(a, c);
}
rep(i, k) {
dijkstra(get<0>(gates[i]), i);
}
vi pos(t + 2, 0);
for (auto [i, l, r] : gates) {
pos[l]++;
pos[r + 1]--;
}
nrep(i, 1, t) {
pos[i] += pos[i - 1];
}
vl ans(t + 2, 0);
rep(i, n) {
priority_queue<pair<ll, int>> pq;
rep(j, k) {
pq.emplace(dis[i][j], j);
}
set<tuple<ll, int ,int>> inter;
while (!pq.empty()) {
auto [c, j] = pq.top();
pq.pop();
auto [n, l, r] = gates[j];
auto itr = inter.begin();
while (itr != inter.end()) {
auto [cost, tl, tr] = *itr;
if (l <= tl && r >= tr) {
inter.erase(make_tuple(cost, tl, tr));
ans[tl] -= cost * fds[i];
ans[tr + 1] += cost * fds[i];
itr = inter.begin();
continue;
}
if (l >= tl && r <= tr) {
inter.erase(make_tuple(cost, tl, tr));
ans[tl] -= cost * fds[i];
ans[tr + 1] += cost * fds[i];
if (l - 1 >= tl) {
inter.emplace(cost, tl, l - 1);
ans[tl] += cost * fds[i];
ans[l] -= cost * fds[i];
}
if (r + 1 <= tr) {
inter.emplace(cost, r + 1, tr);
ans[r + 1] += cost * fds[i];
ans[tr + 1] -= cost * fds[i];
}
itr = inter.begin();
continue;
}
if (l >= tl && l <= tr) {
inter.erase(make_tuple(cost, tl, tr));
ans[tl] -= cost * fds[i];
ans[tr + 1] += cost * fds[i];
if (l - 1 >= tl) {
inter.emplace(cost, tl, l - 1);
ans[tl] += cost * fds[i];
ans[l] -= cost * fds[i];
}
itr = inter.begin();
continue;
}
if (r >= tl && r <= tr) {
inter.erase(make_tuple(cost, tl, tr));
ans[tl] -= cost * fds[i];
ans[tr + 1] += cost * fds[i];
if (r + 1 <= tr) {
inter.emplace(cost, r + 1, tr);
ans[r + 1] += cost * fds[i];
ans[tr + 1] -= cost * fds[i];
}
itr = inter.begin();
continue;
}
itr++;
}
inter.emplace(c, l, r);
ans[l] += c * fds[i];
ans[r + 1] -= c * fds[i];
}
}
for (int i = 1; i <= t; i++) {
ans[i] += ans[i - 1];
if (!pos[i]) {
cout << "-1\n";
continue;
}
cout << ans[i] << '\n';
}
}

View File

@@ -0,0 +1,152 @@
/* Problem URL: https://codeforces.com/gym/105316/problem/I */
#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;
}
double dis(ll x1, ll y1, ll x2, ll y2)
{
ll x = x1 - x2;
ll y = y1 - y2;
return sqrt(x * x + y * y);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, q;
cin >> n >> q;
V<pair<int, int>> points;
while (n--) {
int x, y, z;
cin >> x >> y >> z;
for (size_t i = 0; i <= z; i++) {
int yn = y + i;
int xn = x;
while (dis(xn, yn, x, y) <= z) {
points.emplace_back(xn, yn);
int dx = xn - x;
int dy = yn - y;
if (dy != 0) {
points.emplace_back(xn, y - dy);
}
if (dx != 0) {
points.emplace_back(x - dx, yn);
}
if (dx != 0 && dy != 0) {
points.emplace_back(x - dx, y - dy);
}
xn++;
}
}
}
sortv(points);
pair<int, int> prev = {-1e6, -1e6};
int now = 1;
V<pair<int, int>> act;
vi count;
for (auto i : points) {
if (i == prev) {
now++;
continue;
}
act.emplace_back(prev);
count.push_back(now);
now = 1;
prev = i;
}
act.emplace_back(prev);
count.push_back(now);
while (q--) {
int x, y;
cin >> x >> y;
auto itr = lower_bound(act.begin(), act.end(), make_pair(x, y));
if (itr == act.end() || *itr != make_pair(x, y)) {
cout << "0\n";
continue;
}
cout << count[itr - act.begin()] << '\n';
}
}
}

View File

@@ -0,0 +1,123 @@
/* Problem URL: https://codeforces.com/gym/105321/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
set<int> divs;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
if (i * i == n) {
divs.insert(i);
continue;
}
divs.insert(n / i);
divs.insert(i);
}
}
if (divs.empty()) {
cout << "1\n1 1\n";
return 0;
}
vi ans;
while (!divs.empty()) {
int now = *divs.rbegin();
divs.erase(prev(divs.end()));
ans.push_back(now);
for (int i = 2; i * i <= now; i++) {
if (now % i == 0) {
divs.erase(i);
divs.erase(now / i);
}
}
}
cout << ans.size() << '\n';
repv(i, ans) {
cout << "1 " << i << '\n';
}
}

View File

@@ -0,0 +1,149 @@
/* Problem URL: https://codeforces.com/gym/105321/problem/J */
#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);
int n;
ll x;
cin >> n >> x;
int lim = x >> 1;
vl fds(n);
cin >> fds;
vl one;
vl two;
int c = 0;
rep(i, n) {
if (fds[i] * 2 == x) {
c++;
continue;
}
if (fds[i] <= lim) {
one.push_back(fds[i]);
continue;
}
two.push_back(fds[i]);
}
sortv(one);
sort(all(two), greater<>());
if (!one.empty() && !two.empty() && one.back() + two.front() == x) {
if (one.front() + two.front() != x) {
reverse(all(one));
} else if (one.back() + two.back() != x) {
reverse(all(two));
}
}
if (c > (n + 1) / 2 || (!one.empty() && !two.empty() && one.back() + two.front() == x && c == 0)) {
cout << "*\n";
return 0;
}
rep(i, one.size()) {
if (c > 1) {
cout << lim << ' ';
c--;
}
cout << one[i] << ' ';
}
if (c) {
cout << lim << ' ';
c--;
}
rep(i, two.size()) {
cout << two[i] << ' ';
if (c) {
cout << lim << ' ';
c--;
}
}
cout << '\n';
}

View File

@@ -0,0 +1,140 @@
/* Problem URL: https://codeforces.com/gym/105535/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vi fds(n);
cin >> fds;
vvi graph(n);
nrep(i, 1, n) {
int a, b;
cin >> a >> b;
a--, b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vi ans;
int total = 0;
function<bool(int, int)> dfs = [&](int i, int p) {
fds[i]--;
total++;
ans.push_back(i + 1);
repv(j, graph[i]) {
if (j == p) {
continue;
}
if (!dfs(j, i) || fds[i] == 0) {
return false;
}
total++;
fds[i]--;
ans.push_back(i + 1);
while (fds[j] > 0) {
if (fds[i] == 0) {
return false;
}
ans.push_back(j + 1);
ans.push_back(i + 1);
fds[i]--;
fds[j]--;
total += 2;
}
}
return true;
};
fds[0]++;
int check = accumulate(all(fds), 0);
if (!dfs(0, 0) || total != check) {
cout << "0\n";
return 0;
}
cout << ans;
}

View File

@@ -0,0 +1,182 @@
/* Problem URL: https://codeforces.com/gym/105164/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;
vvl operator*(vvl &a, vvl &b)
{
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 exp(int n)
{
vvl ans = {
{1},
{0},
{0},
{0},
{0},
{3},
{0},
{0},
{0},
{3},
{0},
{9},
{0},
{3},
{0},
{18},
{0},
{30},
{0},
{27}
};
if (n < 20) {
ll total = 0;
for (int i = 0; i <= n; i++) {
total += ans[i][0];
total %= mod;
}
return total;
}
n -= 20;
vvl tmp(20, vl(20));
rep(i, 19) {
tmp[i][i + 1] = 1;
}
for (int j = 20 - 6; j >= 0; j -= 4) {
tmp[19][j] = 3;
}
rep(i, 31) {
if ((n >> i) & 1) {
ans = tmp * ans;
}
tmp = tmp * tmp;
}
ll total = 0;
rep(i, 20) {
total += ans[i][0];
total %= mod;
}
return total;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
// vl dp(n + 1);
// dp[0] = 1;
//
// for (int i = 1; i <= n; i++) {
// for (int j = i - 6; j >= 0 && abs(i - j) <= 20; j -= 4) {
// dp[i] += dp[j] * 3;
// dp[i] %= mod;
// }
// }
//
// ll total = 0;
// for (int i = max(n - 19, 0); i <= n; i++) {
// total += dp[i];
// total %= mod;
// }
cout << exp(n) << '\n';
// cout << total << '\n';
}
}

View File

@@ -0,0 +1,117 @@
/* Problem URL: https://codeforces.com/gym/105216/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;
}
ll mod = 1e9 + 7;
int dest = 7200;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
vvl dp(801, vl(7201 * 2));
dp[0][dest] = 1;
for (int i = 0; i <= 14400; i++) {
for (int j = 1; j <= 8; j++) {
if (i - j >= 0) {
dp[1][i] += dp[0][i - j] * (9 - j);
}
if (i + j <= 14400) {
dp[1][i] += dp[0][i + j] * (9 - j);
}
dp[1][i] %= mod;
}
}
for (int i = 2; i <= 800; i++) {
for (int j = 0; j <= 14400; j++) {
for (int k = 1; k <= 9; k++) {
if (j - k >= 0) {
dp[i][j] += dp[i - 1][j - k] * (10 - k);
}
if (j + k <= 14400) {
dp[i][j] += dp[i - 1][j + k] * (10 - k);
}
dp[i][j] %= mod;
}
}
}
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
cout << dp[n][dest] << '\n';
}
}

View File

@@ -0,0 +1,111 @@
/* Problem URL: https://codeforces.com/gym/105216/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
V<pair<int, int>> fds(n);
rep(i, n) {
fds[i].second = i;
cin >> fds[i].first;
}
V<pair<int, int>> ans;
vvi graph(n);
vi roots;
int total = 0;
sort(all(fds));
rep(i, n) {
int now = fds[i].first - 1;
if (total < now) {
cout << "-1\n";
return 0;
}
total++;
rep(j, now) {
ans.emplace_back(fds[i].second + 1, fds[j].second + 1);
}
}
cout << ans.size() << '\n';
for (auto [i, j] : ans) {
cout << i << ' ' << j << '\n';
}
}

View File

@@ -0,0 +1,124 @@
/* Problem URL: https://codeforces.com/gym/105216/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 (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, m;
cin >> n >> m;
if (n == 1) {
cout << "NO\n";
return 0;
}
V<pair<int, int>> ans;
V<V<bool>> connect(n, V<bool>(n));
while (m--) {
int a, b;
cin >> a >> b;
a--, b--;
connect[a][b] = true;
connect[b][a] = true;
}
cout << "YES\n";
rep(i, n / 2) {
nrep(j, i + 1, n / 2) {
if (!connect[i][j]) {
connect[i][j] = true;
connect[j][i] = true;
ans.emplace_back(i + 1, j + 1);
}
}
}
nrep(i, n / 2, n) {
nrep(j, i + 1, n) {
if (!connect[i][j]) {
connect[i][j] = true;
connect[j][i] = true;
ans.emplace_back(i + 1, j + 1);
}
}
}
cout << ans.size() << '\n';
for (auto [i, j] : ans) {
cout << i << ' ' << j << '\n';
}
}

View File

@@ -0,0 +1,99 @@
/* Problem URL: https://codeforces.com/gym/105446/problem/A */
#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);
string a, b;
cin >> a >> b;
vi counta(26);
vi countb(26);
repv(i, a) {
counta[i - 'a']++;
}
repv(i, b) {
countb[i - 'a']++;
}
rep(i, 26) {
int now = max(counta[i], countb[i]);
while (now--) {
cout << (char)(i + 'a');
}
}
cout << '\n';
}

View File

@@ -0,0 +1,123 @@
/* Problem URL: https://codeforces.com/gym/105446/problem/D */
#include <bits/stdc++.h>
#include <algorithm>
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 q;
cin >> q;
while (q--) {
double p, r, y;
cin >> p >> r >> y;
double low = -1.5;
double high = 1.5;
while (high - low >= 1e-10) {
double third = (high - low) / 3;
double mid1 = low + third;
double mid2 = high - third;
auto check = [&](double mid) {
double w = mid;
double s = (y - p - r) / 2 + w;
double n = r + s;
double e = p + w;
return max({abs(w), abs(s), abs(n), abs(e)});
};
if (check(mid1) < check(mid2)) {
high = mid1;
continue;
}
if (check(mid1) > check(mid2)) {
low = mid2;
continue;
}
low = mid1;
high = mid2;
}
double w = low;
double s = (y - p - r) / 2 + w;
double n = r + s;
double e = p + w;
cout << fixed << setprecision(6) << n << ' ' << e << ' ' << s << ' ' << w << '\n';
}
}

View File

@@ -0,0 +1,140 @@
/* Problem URL: https://codeforces.com/gym/105446/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, l, k;
cin >> n >> l >> k;
V<bool> vis(n);
V<string> rev(n);
vvi s(n, vi(l));
rep(i, n) {
string fds;
cin >> fds;
rev[i] = fds;
rep(j, l) {
cin >> s[i][j];
}
}
auto diff = [&](int i, int j) {
int ans = 0;
rep(f, l) {
ans += abs(s[i][f] - s[j][f]);
}
return ans;
};
vi dis(n, INT32_MAX);
vi choices;
int now = 0;
int maximal = 0;
nrep(i, 1, n) {
int d = diff(0, i);
if (d > maximal) {
maximal = d;
now = i;
}
}
choices.push_back(now);
nrep(i, 1, k) {
now = 0;
maximal = 0;
rep(j, n) {
rmin(dis[j], diff(choices.back(), j));
if (dis[j] > maximal) {
maximal = dis[j];
now = j;
}
}
choices.push_back(now);
}
repv(i, choices) {
cout << rev[i] << '\n';
}
}

View File

@@ -0,0 +1,146 @@
/* Problem URL: https://codeforces.com/problemset/problem/2045/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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
void solve()
{
string s, t;
cin >> s >> t;
int in = -1;
int jn = -1;
int ans = oo;
vi pos(26, -1);
rep(i, t.size() - 1) {
pos[t[i] - 'a'] = i;
}
nrep(i, 1, s.size()) {
int cur = s[i] - 'a';
if (pos[cur] == -1) {
continue;
}
int c = i + t.size() - pos[cur] + 1;
if (c < ans) {
ans = c;
in = i;
jn = pos[cur];
}
}
if (ans == oo) {
cout << "-1\n";
return;
}
rep(i, in) {
cout << s[i];
}
nrep(j, jn, t.size()) {
cout << t[j];
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,248 @@
/* Problem URL: https://codeforces.com/problemset/problem/2045/M */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
void solve()
{
int r, c;
cin >> r >> c;
V<string> a(r);
cin >> a;
auto getpos = [&](int i, int j, int k) {
return i * c * 4 + j * 4 + k;
};
int tot = 0;
vvi graph(r * c * 4);
vi ty(r * c * 4, -1);
rep(i, r) {
rep(j, c) {
int n = getpos(i, j, 0);
int e = getpos(i, j, 1);
int s = getpos(i, j, 2);
int w = getpos(i, j, 3);
if (i > 0) {
int ot = getpos(i - 1, j, 2);
graph[n].push_back(ot);
}
if (j > 0) {
int ot = getpos(i, j - 1, 1);
graph[w].push_back(ot);
}
if (i < r - 1) {
int ot = getpos(i + 1, j, 0);
graph[s].push_back(ot);
}
if (j < c - 1) {
int ot = getpos(i, j + 1, 3);
graph[e].push_back(ot);
}
if (a[i][j] == '.') {
graph[e].push_back(w);
graph[w].push_back(e);
graph[s].push_back(n);
graph[n].push_back(s);
continue;
}
tot++;
ty[n] = i * c + j;
ty[e] = i * c + j;
ty[s] = i * c + j;
ty[w] = i * c + j;
if (a[i][j] == '/') {
graph[n].push_back(w);
graph[w].push_back(n);
graph[s].push_back(e);
graph[e].push_back(s);
continue;
}
graph[n].push_back(e);
graph[e].push_back(n);
graph[w].push_back(s);
graph[s].push_back(w);
}
}
V<bool> vis(r * c * 4);
vi sz(r * c * 4, -1);
set<int> s;
function<void(int)> dfs = [&](int i) {
vis[i] = true;
if (ty[i] != -1) {
s.insert(ty[i]);
}
repv(j, graph[i]) {
if (vis[j]) {
continue;
}
dfs(j);
}
};
function<void(int)> dfs2 = [&](int i) {
sz[i] = s.size();
repv(j, graph[i]) {
if (sz[j] != -1) {
continue;
}
dfs2(j);
}
};
rep(i, r) {
rep(j, c) {
rep(k, 4) {
int ac = getpos(i, j, k);
if (vis[ac]) {
continue;
}
dfs(ac);
dfs2(ac);
s.clear();
}
}
}
V<string> ans;
rep(i, r) {
int w = getpos(i, 0, 3);
if (sz[w] == tot) {
ans.emplace_back("W" + to_string(i + 1));
}
int e = getpos(i, c - 1, 1);
if (sz[e] == tot) {
ans.emplace_back("E" + to_string(i + 1));
}
}
rep(i, c) {
int n = getpos(0, i, 0);
if (sz[n] == tot) {
ans.emplace_back("N" + to_string(i + 1));
}
int s = getpos(r - 1, i, 2);
if (sz[s] == tot) {
ans.emplace_back("S" + to_string(i + 1));
}
}
cout << ans.size() << '\n';
repv(i, ans) {
cout << i << ' ';
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,81 @@
/* Problem URL: https://codeforces.com/gym/105327/problem/A */
#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, k;
cin >> n >> k;
cout << (k - (k / n) * n >= (n - 1) ? k / n : k / n - 1) << '\n';
}

View File

@@ -0,0 +1,239 @@
/* Problem URL: https://codeforces.com/gym/105327/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vvi tree(n + m);
vi dsu(n + m);
rep(i, dsu.size()) {
dsu[i] = i;
}
function<int(int)> find_p = [&](int i) {
if (dsu[i] == i) {
return i;
}
return dsu[i] = find_p(dsu[i]);
};
auto join = [&](int a, int b) {
a = find_p(a);
b = find_p(b);
if (a == b) {
return false;
}
dsu[a] = b;
return true;
};
rep(i, n) {
int k;
cin >> k;
while (k--) {
int j;
cin >> j;
j--;
if (!join(i, j + n)) {
continue;
}
tree[i].push_back(j + n);
tree[j + n].push_back(i);
}
}
vvi parent(n + m, vi(25));
vi depth(n + m, -1);
vi group(n + m, -1);
int g = 0;
V<bool> vis(n + m);
function<void(int, int)> buildlca = [&](int i, int p) {
parent[i][0] = p;
depth[i] = depth[p] + 1;
group[i] = g;
vis[i] = true;
nrep(j, 1, 25) {
parent[i][j] = parent[parent[i][j - 1]][j - 1];
}
for (auto j : tree[i]) {
if (j == p) {
continue;
}
buildlca(j, i);
}
};
rep(i, n + m) {
if (vis[i]) {
continue;
}
buildlca(i, i);
g++;
}
auto lca = [&](int a, int b) {
if (depth[a] > depth[b]) {
swap(a, b);
}
int diff = depth[b] - depth[a];
rep(i, 25) {
if ((diff >> i) & 1) {
b = parent[b][i];
}
}
if (a == b) {
return a;
}
for (int i = 24; i >= 0; i--) {
if (parent[a][i] == parent[b][i]) {
continue;
}
a = parent[a][i];
b = parent[b][i];
}
return parent[a][0];
};
int q;
cin >> q;
while (q--) {
int a, b;
cin >> a >> b;
a--, b--;
a += n;
b += n;
if (group[a] != group[b]) {
cout << "-1\n";
continue;
}
int p = lca(a, b);
vi ans1;
vi ans2;
while (a != p) {
ans1.push_back(a + 1);
a = parent[a][0];
}
ans1.push_back(a + 1);
while (b != p) {
ans2.push_back(b + 1);
b = parent[b][0];
}
reverse(all(ans2));
cout << (ans1.size() + ans2.size() + 1) / 2 << '\n';
repv(i, ans1) {
cout << i - (i > n ? n : 0) << ' ';
}
repv(i, ans2) {
cout << i - (i > n ? n : 0) << ' ';
}
cout << '\n';
}
}

View File

@@ -0,0 +1,117 @@
/* Problem URL: https://codeforces.com/gym/105327/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vvi fds(n, vi(n));
cin >> fds;
int ans = 0;
auto valid = [&]() {
rep(i, n) {
nrep(j, 1, n) {
if (fds[i][j] <= fds[i][j - 1]) {
return false;
}
if (fds[j][i] <= fds[j - 1][i]) {
return false;
}
}
}
return true;
};
auto rotate = [&]() {
vvi tmp = fds;
rep(i, n) {
rep(j, n) {
fds[i][j] = tmp[j][n - i - 1];
}
}
};
while (!valid()) {
ans++;
rotate();
}
cout << ans << '\n';
}

View File

@@ -0,0 +1,89 @@
/* Problem URL: https://codeforces.com/gym/105327/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
ll a = 0;
ll b = 1;
while (n--) {
swap(a, b);
b += a;
}
cout << b << '\n';
}

View File

@@ -0,0 +1,167 @@
/* Problem URL: https://codeforces.com/problemset/problem/2052/F */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
int n;
cin >> n;
array<string, 2> a;
cin >> a[0] >> a[1];
vvi memo(n, vi(4, -1));
function<int(int, int)> dp = [&](int i, int mask) -> int {
if (i >= n) {
return mask == 0;
}
int &ans = memo[i][mask];
if (ans != -1) {
return ans;
}
ans = 0;
int bit1 = mask & 1;
int bit2 = (mask >> 1) & 1;
if ((bit1 && a[0][i] == '#') || (bit2 && a[1][i] == '#')) {
return 0;
}
if (mask == 0 && a[0][i] == '.' && a[1][i] == '.') {
ans = dp(i + 1, 0) + dp(i + 1, 3);
rmin(ans, 2);
} else {
int now = 0;
if (!bit1 && a[0][i] == '.') {
now |= 1;
}
if (!bit2 && a[1][i] == '.') {
now |= 2;
}
ans += dp(i + 1, now);
rmin(ans, 2);
}
return ans;
};
int ans = dp(0, 0);
if (ans == 0) {
cout << "None\n";
return;
}
if (ans == 1) {
cout << "Unique\n";
return;
}
if (ans == 2) {
cout << "Multiple\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,140 @@
/* Problem URL: https://codeforces.com/problemset/problem/2038/A */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
void solve()
{
int n, k;
cin >> n >> k;
vl a(n);
vl b(n);
cin >> a >> b;
ll total = 0;
vl ans(n);
rep(i, n) {
ans[i] = a[i] / b[i];
total += ans[i];
}
if (total < k) {
rep(i, n) {
cout << "0" << " \n"[i == n - 1];
}
return;
}
int inc = total - k;
rep(i, n) {
if (ans[i] < inc) {
inc -= ans[i];
ans[i] = 0;
continue;
}
ans[i] -= inc;
break;
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,141 @@
/* Problem URL: https://codeforces.com/gym/106054/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
const ll mod = 998244353;
auto fpow = [&](ll a, ll p) {
ll ans = 1;
rep(i, 31) {
if ((p >> i) & 1) {
ans *= a;
ans %= mod;
}
a *= a;
a %= mod;
}
return ans;
};
auto comb = [&](ll n, ll k) {
ll ans = 1;
ll div = 1;
rep(i, k) {
ans *= (n - i);
ans %= mod;
div *= (i + 1);
div %= mod;
}
return (ans * fpow(div, mod - 2)) % mod;
};
vl b(n - k + 1);
cin >> b;
ll ans = b[0];
rep(i, k) {
ll m = 0;
ll tmp = 0;
for (int j = i; j + 1 < b.size(); j += k) {
m += b[j] - b[j + 1];
rmax(tmp, m);
}
ans -= tmp;
}
if (ans < 0) {
cout << "0\n";
return 0;
}
cout << comb(ans + k - 1, k - 1) << '\n';
}

View File

@@ -0,0 +1,150 @@
/* Problem URL: https://codeforces.com/problemset/problem/2172/M */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
void solve()
{
int n, m, k;
cin >> n >> m >> k;
vi ans(k);
vi type(n);
rep(i, n) {
int t;
cin >> t;
type[i] = t - 1;
}
vvi graph(n);
while (m--) {
int a, b;
cin >> a >> b;
a--, b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
queue<int> q;
vi dis(n, oo);
dis[0] = 0;
q.push(0);
while (!q.empty()) {
auto i = q.front();
q.pop();
repv(j, graph[i]) {
if (dis[j] > dis[i] + 1) {
dis[j] = dis[i] + 1;
q.push(j);
}
}
}
rep(i, n) {
rmax(ans[type[i]], dis[i]);
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,138 @@
/* Problem URL: https://codeforces.com/contest/2181/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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
int n, m;
cin >> n >> m;
multiset<ll, greater<>> a[2];
rep(i, n) {
ll b;
cin >> b;
a[0].insert(b);
}
rep(i, m) {
ll b;
cin >> b;
a[1].insert(b);
}
int now = 0;
while (!a[now].empty()) {
ll ca = *a[now].begin();
ll cb = *a[now^1].begin();
a[now^1].erase(a[now^1].begin());
now ^= 1;
cb -= ca;
if (cb > 0) {
a[now].insert(cb);
}
}
string win[] = {"Bob", "Alice"};
cout << win[now] << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,118 @@
/* Problem URL: https://codeforces.com/problemset/problem/2181/F */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
int n;
cin >> n;
vl a(n);
cin >> a;
int c = 0;
bool t = false;
rep(i, n) {
c += a[i] == 1;
t = t || a[i] != 1;
}
cout << (((c & 1) && !t) || ((~c & 1) && t) ? "Alice\n" : "Bob\n");
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,119 @@
/* Problem URL: https://codeforces.com/problemset/problem/2181/M */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
string a, b;
cin >> a >> b;
int n = a.size();
vvi dp(n, vi(2));
dp[n - 1][0] = b[n - 1] != '0';
dp[n - 1][1] = b[n - 1] != '1';
for (int i = n - 2; i >= 0; i--) {
dp[i][0] = (b[i] != '0') + min(dp[i + 1][1] + (a[i + 1] != '1'), dp[i + 1][0] + (a[i + 1] != '0'));
dp[i][1] = (b[i] != '1') + min(dp[i + 1][0] + (a[i + 1] != '1'), dp[i + 1][1] + (a[i + 1] != '0'));
}
cout << min(dp[0][0] + (a[0] != '0'), dp[0][1] + (a[0] != '1')) << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,201 @@
/* Problem URL: https://codeforces.com/contest/626/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;
}
#define double long double
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vl fds(n);
cin >> fds;
sortv(fds);
pair<int, int> median = {0, 0};
double ans = 0;
int dev = 0;
vl pref(n + 1);
rep(i, n) {
pref[i + 1] = pref[i] + fds[i];
}
auto search = [&](int med, int devi, int i) {
int low = 1;
int high = devi;
ll ans = 0;
while (low <= high) {
int third = (high - low) / 3;
int mid1 = low + third;
int mid2 = high - third;
double ans1 = (double)(pref[i + 1] - pref[i - mid1] + pref[n] - pref[n - mid1]) / (mid1 * 2 + med) - fds[i];
double ans2 = (double)(pref[i + 1] - pref[i - mid2] + pref[n] - pref[n - mid2]) / (mid2 * 2 + med) - fds[i];
if (ans1 > ans2) {
ans = mid1;
high = mid2 - 1;
continue;
}
if (ans2 > ans1) {
ans = mid2;
low = mid1 + 1;
continue;
}
ans = mid1;
low = mid1 + 1;
high = mid2 - 1;
}
return ans;
};
auto search2 = [&](int med, int devi, int i) {
int low = 1;
int high = devi;
ll ans = 0;
while (low <= high) {
int third = (high - low) / 3;
int mid1 = low + third;
int mid2 = high - third;
double ans1 = (double)(pref[i + 2] - pref[i - mid1] + pref[n] - pref[n - mid1]) / (mid1 * 2 + med) - (fds[i] + fds[i + 1]) / 2.0L;
double ans2 = (double)(pref[i + 2] - pref[i - mid2] + pref[n] - pref[n - mid2]) / (mid2 * 2 + med) - (fds[i] + fds[i + 1]) / 2.0L;
if (ans1 > ans2) {
ans = mid1;
high = mid2 - 1;
continue;
}
if (ans2 > ans1) {
ans = mid2;
low = mid1 + 1;
continue;
}
ans = mid1;
low = mid1 + 1;
high = mid2 - 1;
}
return ans;
};
rep(i, n) {
int devi = min(i, n - i - 1);
int best = search(1, devi, i);
double tmp = (double)(pref[i + 1] - pref[i - best] + pref[n] - pref[n - best]) / (best * 2 + 1) - fds[i];
if (tmp >= ans) {
ans = tmp;
median = {i, i};
dev = best;
}
}
rep(i, n - 1) {
int devi = min(i, n - i - 2);
int best = search2(2, devi, i);
double tmp = (double)(pref[i + 2] - pref[i - best] + pref[n] - pref[n - best]) / (best * 2 + 2) - (fds[i] + fds[i + 1]) / 2.0L;
if (tmp >= ans) {
ans = tmp;
median = {i, i + 1};
dev = best;
}
}
int size = dev * 2 + (median.first != median.second) + 1;
cout << size << '\n';
nrep(i, median.first - dev, median.first) {
cout << fds[i] << ' ';
}
cout << fds[median.first] << ' ';
if (median.first != median.second) {
cout << fds[median.second] << ' ';
}
nrep(i, n - dev, n) {
cout << fds[i] << ' ';
}
cout << '\n';
}

View File

@@ -0,0 +1,108 @@
/* Problem URL: https://codeforces.com/problemset/problem/2127/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;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
string a;
cin >> a;
x--;
int l = -1;
rep(i, x) {
if (a[i] == '#') {
l = i;
}
}
int r = n;
for (int i = n - 1; i > x; i--) {
if (a[i] == '#') {
r = i;
}
}
cout << max(min(x + 1, n - r + 1), min(l + 2, n - x)) << '\n';
}
}

View File

@@ -0,0 +1,152 @@
/* Problem URL: https://codeforces.com/contest/2127/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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
int n, k;
cin >> n >> k;
vl a(n);
vl b(n);
cin >> a >> b;
rep(i, n) {
if (a[i] > b[i]) {
swap(a[i], b[i]);
}
}
vi perm(n);
rep(i, n) {
perm[i] = i;
}
sort(all(perm), [&](int i, int j) {
if (a[i] == a[j]) {
return b[i] > b[j];
}
return a[i] < a[j];
});
ll ans = 0;
rep(i, n) {
ans += abs(a[i] - b[i]);
}
ll minimal = OO;
{
ll r = b[perm[0]];
nrep(i, 1, n) {
if (a[perm[i]] <= r) {
cout << ans << '\n';
return;
}
rmin(minimal, a[perm[i]] - r);
rmax(r, b[perm[i]]);
}
}
cout << ans + minimal * 2 << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,183 @@
/* Problem URL: https://codeforces.com/problemset/problem/475/D */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
void solve()
{
int n;
cin >> n;
vl a(n);
cin >> a;
// map<ll, ll> count;
//
// V<map<ll, ll>> g(n);
// g[0][a[0]] = 1;
// count[a[0]]++;
//
// nrep(i, 1, n) {
// g[i][a[i]] = 1;
// repv(j, g[i - 1]) {
// g[i][gcd(a[i], j.first)] += j.second;
// }
//
// repv(j, g[i]) {
// count[j.first] += j.second;
// }
// }
//
// int q;
// cin >> q;
// while (q--) {
// ll a;
// cin >> a;
// cout << count[a] << '\n';
// }
vvl sparse(20, vl(n));
rep(i, n) {
sparse[0][i] = a[i];
}
nrep(j, 1, 20) {
for (int i = 0; i + (1 << (j - 1)) < n; i++) {
sparse[j][i] = gcd(sparse[j - 1][i], sparse[j - 1][i + (1 << (j - 1))]);
}
}
auto query = [&](ll l, ll r) {
ll log = 31 - __builtin_clz(r - l + 1);
return gcd(sparse[log][l], sparse[log][r - (1 << log) + 1]);
};
map<ll, ll> count;
rep(i, n) {
ll r = i;
while (r < n) {
ll low = r;
ll high = n - 1;
ll cur = r;
while (low <= high) {
ll mid = (low + high) >> 1;
if (query(i, r) == query(i, mid)) {
cur = mid;
low = mid + 1;
continue;
}
high = mid - 1;
}
count[query(i, cur)] += cur - r + 1;
r = cur + 1;
}
}
int q;
cin >> q;
while (q--) {
ll x;
cin >> x;
cout << count[x] << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,122 @@
/* Problem URL: https://codeforces.com/contest/717/problem/D */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
void solve()
{
int n, x;
cin >> n >> x;
x++;
V<long double> p(x);
cin >> p;
V<long double> act(4);
rep(i, x) {
rep(j, 4) {
if ((i >> j) & 1) {
act[j] += p[i];
}
}
}
cout << act;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,148 @@
/* Problem URL: https://codeforces.com/contest/1866/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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 0
void solve()
{
int n;
cin >> n;
vi x1(n);
vi x2(n);
cin >> x1 >> x2;
int m;
cin >> m;
vi y1(m);
vi y2(m);
cin >> y1 >> y2;
vi x(2e6 + 1);
vi y(2e6 + 1);
rep(i, n) {
x[x1[i]] = x2[i];
}
rep(i, m) {
y[y1[i]] = y2[i];
}
rep(i, 2e6 + 1) {
if (x[i] < y[i]) {
cout << "0\n";
return;
}
}
ll ans = 1;
const ll mod = 998244353;
rep(i, 2e6 + 1) {
if (x[i] > y[i]) {
ans = (ans << 1) % mod;
}
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,221 @@
/* Problem URL: https://codeforces.com/problemset/problem/1896/D */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
int n, q;
cin >> n >> q;
vi a(n);
cin >> a;
while (__builtin_popcount(n) != 1) {
n++;
a.push_back(0);
}
set<int> ones;
rep(i, n) {
if (a[i] == 1) {
ones.insert(i);
}
}
vi seg(n << 1);
nrep(i, n, n << 1) {
seg[i] = a[i - n];
}
for (int i = n - 1; i > 0; i--) {
seg[i] = seg[i * 2] + seg[i * 2 + 1];
}
auto update = [&](int i, int v) {
i += n;
seg[i] = v;
for (i >>= 1; i > 0; i >>= 1) {
seg[i] = seg[i * 2] + seg[i * 2 + 1];
}
};
function<int(int, int, int, int, int)> query = [&](int i, int l, int r, int tl, int tr) {
if (l > tr || r < tl) {
return 0;
}
if (l >= tl && r <= tr) {
return seg[i];
}
int mid = (l + r) >> 1;
return query(i * 2, l, mid, tl, tr) + query(i * 2 + 1, mid + 1, r, tl, tr);
};
int l1 = -1;
int r1 = -1;
if (!ones.empty()) {
l1 = *ones.begin();
r1 = *prev(ones.end());
}
while (q--) {
int op;
cin >> op;
if (op == 2) {
int i, v;
cin >> i >> v;
i--;
if (a[i] == 1) {
ones.erase(i);
}
a[i] = v;
update(i, v);
if (v == 1) {
ones.insert(i);
}
if (!ones.empty()) {
l1 = *ones.begin();
r1 = *prev(ones.end());
} else {
l1 = -1;
r1 = -1;
}
continue;
}
int s;
cin >> s;
if (s & 1) {
if (l1 == -1) {
cout << "NO\n";
continue;
}
if (ones.size() & 1) {
cout << (query(1, 0, n - 1, 0, n - 1) >= s ? "YES\n" : "NO\n");
continue;
}
int ans = max(query(1, 0, n - 1, 0, r1 - 1), query(1, 0, n - 1, l1 + 1, n - 1));
cout << (ans >= s ? "YES\n" : "NO\n");
continue;
}
if (ones.size() & 1) {
int ans = max(query(1, 0, n - 1, 0, r1 - 1), query(1, 0, n - 1, l1 + 1, n - 1));
cout << (ans >= s ? "YES\n" : "NO\n");
continue;
}
cout << (query(1, 0, n - 1, 0, n - 1) >= s ? "YES\n" : "NO\n");
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

View File

@@ -0,0 +1,164 @@
/* Problem URL: https://codeforces.com/problemset/problem/1942/C2 */
#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;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
void pre()
{
}
#define TEST 1
void solve()
{
int n, x, y;
cin >> n >> x >> y;
ll ini = y;
vi a(x);
cin >> a;
sortv(a);
ll ans = x - 2;
ll even = 0;
vl odds;
nrep(i, 1, x) {
if (a[i] - a[i - 1] - 1 <= 1) {
ans += a[i] - a[i - 1] - 1;
continue;
}
ll g = a[i] - a[i - 1] - 1;
if (g & 1) {
odds.push_back(g >> 1);
continue;
}
even += g >> 1;
}
ll g = n - (a.back() - a[0] + 1);
if (g <= 1) {
ans += g;
} else if (g & 1) {
odds.push_back(g >> 1);
} else {
even += g >> 1;
}
sortv(odds);
repv(i, odds) {
if (y >= i) {
y -= i;
ans += i + 1;
continue;
}
ans += y;
y = 0;
break;
}
ll ev = min(even, (ll)y);
y -= ev;
ans += ev;
ll us = ini - y;
ans += us;
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}

Some files were not shown because too many files have changed in this diff Show More