Add a bunch of other problems.
This commit is contained in:
111
Codeforces Round 1067 (Div. 2)/A. Suspension.cpp
Normal file
111
Codeforces Round 1067 (Div. 2)/A. Suspension.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2158/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;
|
||||
|
||||
|
||||
void pre()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#define TEST 1
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int y, r;
|
||||
cin >> y >> r;
|
||||
|
||||
cout << min(y / 2 + r, n) << '\n';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
150
Codeforces Round 1067 (Div. 2)/B. Split.cpp
Normal file
150
Codeforces Round 1067 (Div. 2)/B. Split.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2158/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;
|
||||
cin >> n;
|
||||
n <<= 1;
|
||||
vi a(n);
|
||||
cin >> a;
|
||||
|
||||
sortv(a);
|
||||
vi count = {1};
|
||||
nrep(i, 1, n) {
|
||||
if (a[i] != a[i - 1]) {
|
||||
count.emplace_back();
|
||||
}
|
||||
|
||||
count.back()++;
|
||||
}
|
||||
|
||||
if (count.size() == 1) {
|
||||
cout << (((n >> 1) & 1) << 1) << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
int c = 0;
|
||||
rep(i, count.size()) {
|
||||
if (count[i] & 1) {
|
||||
ans++;
|
||||
continue;
|
||||
}
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
if (ans > 0) {
|
||||
c <<= 1;
|
||||
} else {
|
||||
if (((n >> 1) & 1)) {
|
||||
c -= ~c & 1;
|
||||
c <<= 1;
|
||||
} else {
|
||||
c -= c & 1;
|
||||
c <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans + c << '\n';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
147
Codeforces Round 1067 (Div. 2)/C. Annoying Game.cpp
Normal file
147
Codeforces Round 1067 (Div. 2)/C. Annoying Game.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2158/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;
|
||||
|
||||
if (n == 1) {
|
||||
cout << a[0] + b[0] * (k & 1) << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
vl pref(n);
|
||||
vl suf(n);
|
||||
|
||||
ll kanp = 0;
|
||||
ll kans = 0;
|
||||
|
||||
ll ans = -OO;
|
||||
|
||||
rep(i, n) {
|
||||
kanp += a[i];
|
||||
kans += a[n - i - 1];
|
||||
|
||||
ans = max({ans, kanp, kans});
|
||||
|
||||
rmax(kanp, 0LL);
|
||||
rmax(kans, 0LL);
|
||||
|
||||
pref[i] = kanp;
|
||||
suf[n - i - 1] = kans;
|
||||
}
|
||||
|
||||
if (k & 1) {
|
||||
rmax(ans, suf[1] + b[0] + a[0]);
|
||||
rmax(ans, pref[n - 2] + b[n - 1] + a[n - 1]);
|
||||
nrep(i, 1, n - 1) {
|
||||
rmax(ans, pref[i - 1] + suf[i + 1] + a[i] + b[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();
|
||||
}
|
||||
}
|
||||
186
Codeforces Round 1067 (Div. 2)/D. Palindrome Flipping.cpp
Normal file
186
Codeforces Round 1067 (Div. 2)/D. Palindrome Flipping.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2158/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;
|
||||
|
||||
|
||||
map<string, pair<V<pair<int, int>>, char>> ops;
|
||||
map<string, V<pair<int, int>>> getlast[2];
|
||||
void pre()
|
||||
{
|
||||
ops["0000"] = {{}, '0'};
|
||||
ops["0001"] = {{{1, 3}}, '1'};
|
||||
ops["0010"] = {{{1, 2}, {1, 3}}, '0'};
|
||||
ops["0011"] = {{{1, 2}}, '1'};
|
||||
ops["0100"] = {{{3, 4}, {2, 4}}, '0'};
|
||||
ops["0101"] = {{{1, 3}, {3, 4}, {2, 4}}, '1'};
|
||||
ops["0110"] = {{{2, 3}}, '0'};
|
||||
ops["0111"] = {{{2, 4}}, '0'};
|
||||
ops["1000"] = {{{2, 4}}, '1'};
|
||||
ops["1001"] = {{{2, 3}}, '1'};
|
||||
ops["1010"] = {{{1, 3}, {3, 4}, {2, 4}}, '0'};
|
||||
ops["1011"] = {{{3, 4}, {2, 4}}, '1'};
|
||||
ops["1100"] = {{{1, 2}}, '0'};
|
||||
ops["1101"] = {{{1, 2}, {1, 3}}, '1'};
|
||||
ops["1110"] = {{{1, 3}}, '0'};
|
||||
ops["1111"] = {{}, '1'};
|
||||
|
||||
getlast[0]["0000"] = {};
|
||||
getlast[0]["0001"] = {{1, 4}, {1, 3}};
|
||||
getlast[0]["0010"] = {{1, 3}, {1, 2}};
|
||||
getlast[0]["0011"] = {{3, 4}};
|
||||
getlast[0]["0100"] = {{2, 4}, {3, 4}};
|
||||
getlast[0]["0101"] = {{1, 3}, {1, 2}, {2, 4}};
|
||||
getlast[0]["0110"] = {{2, 3}};
|
||||
getlast[0]["0111"] = {{2, 4}};
|
||||
getlast[0]["1000"] = {{1, 4}, {2, 4}};
|
||||
getlast[0]["1001"] = {{2, 3}, {1, 4}};
|
||||
getlast[0]["1010"] = {{2, 4}, {3, 4}, {1, 3}};
|
||||
getlast[0]["1011"] = {{1, 4}, {2, 4}, {3, 4}};
|
||||
getlast[0]["1100"] = {{1, 2}};
|
||||
getlast[0]["1101"] = {{1, 4}, {1, 3}, {1, 2}};
|
||||
getlast[0]["1110"] = {{1, 3}};
|
||||
getlast[0]["1111"] = {{1, 4}};
|
||||
|
||||
getlast[1]["1111"] = {};
|
||||
getlast[1]["1110"] = {{1, 4}, {1, 3}};
|
||||
getlast[1]["1101"] = {{1, 3}, {1, 2}};
|
||||
getlast[1]["1100"] = {{3, 4}};
|
||||
getlast[1]["1011"] = {{2, 4}, {3, 4}};
|
||||
getlast[1]["1010"] = {{1, 3}, {1, 2}, {2, 4}};
|
||||
getlast[1]["1001"] = {{2, 3}};
|
||||
getlast[1]["1000"] = {{2, 4}};
|
||||
getlast[1]["0111"] = {{1, 4}, {2, 4}};
|
||||
getlast[1]["0110"] = {{2, 3}, {1, 4}};
|
||||
getlast[1]["0101"] = {{2, 4}, {3, 4}, {1, 3}};
|
||||
getlast[1]["0100"] = {{1, 4}, {2, 4}, {3, 4}};
|
||||
getlast[1]["0011"] = {{1, 2}};
|
||||
getlast[1]["0010"] = {{1, 4}, {1, 3}, {1, 2}};
|
||||
getlast[1]["0001"] = {{1, 3}};
|
||||
getlast[1]["0000"] = {{1, 4}};
|
||||
}
|
||||
|
||||
#define TEST 1
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
string a, b;
|
||||
cin >> a >> b;
|
||||
|
||||
auto [ans, cur] = ops[a.substr(0, 4)];
|
||||
|
||||
nrep(i, 4, n) {
|
||||
if (a[i] != cur) {
|
||||
ans.emplace_back(1, i);
|
||||
cur = a[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = n - 1; i > 3; i--) {
|
||||
if (b[i] != cur) {
|
||||
ans.emplace_back(1, i + 1);
|
||||
cur = b[i];
|
||||
}
|
||||
}
|
||||
|
||||
auto bf = getlast[cur - '0'][b.substr(0, 4)];
|
||||
repv(i, bf) {
|
||||
ans.emplace_back(i);
|
||||
}
|
||||
|
||||
cout << ans.size() << '\n';
|
||||
repv(i, ans) {
|
||||
cout << i.first << ' ' << i.second << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user