Add more problems
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/2039/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, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vi a(m);
|
||||
cin >> a;
|
||||
sort(all(a), greater<>());
|
||||
|
||||
if (n == 1) {
|
||||
cout << a[0] << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
if (m == 1) {
|
||||
cout << "-1\n";
|
||||
return;
|
||||
}
|
||||
|
||||
set<int> all;
|
||||
nrep(i, 1, n + 1) {
|
||||
all.insert(i);
|
||||
}
|
||||
|
||||
vi ans(n);
|
||||
rep(i, m) {
|
||||
if (all.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto itr = all.begin();
|
||||
int cur = *itr;
|
||||
ans[*itr - 1] = a[i];
|
||||
itr = all.erase(itr);
|
||||
|
||||
while (itr != all.end()) {
|
||||
if (*itr % cur == 0) {
|
||||
itr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
ans[*itr - 1] = a[i];
|
||||
itr = all.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!all.empty()) {
|
||||
cout << "-1\n";
|
||||
return;
|
||||
}
|
||||
|
||||
cout << ans;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
123
Codeforces Round 1004 (Div. 2)/C. Devyatkino.cpp
Normal file
123
Codeforces Round 1004 (Div. 2)/C. Devyatkino.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/2067/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()
|
||||
{
|
||||
ll n;
|
||||
cin >> n;
|
||||
|
||||
rep(k, 8) {
|
||||
string now = to_string(n - k);
|
||||
|
||||
int cur = 0;
|
||||
repv(i, now) {
|
||||
if (i <= '7') {
|
||||
rmax(cur, i - '0');
|
||||
}
|
||||
}
|
||||
|
||||
if (k >= 7 - cur) {
|
||||
cout << k << '\n';
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/2129/C1 */
|
||||
|
||||
#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;
|
||||
|
||||
string ans(n, ' ');
|
||||
|
||||
vi pos(n);
|
||||
rep(i, n) {
|
||||
pos[i] = i + 1;
|
||||
}
|
||||
bool rev = false;
|
||||
|
||||
int total;
|
||||
cout << "? " << n;
|
||||
nrep(i, 1, n + 1) {
|
||||
cout << ' ' << i;
|
||||
}
|
||||
cout << endl;
|
||||
cin >> total;
|
||||
|
||||
if (total == 0) {
|
||||
rev = true;
|
||||
reverse(all(pos));
|
||||
cout << "? " << n;
|
||||
rep(i, n) {
|
||||
cout << ' ' << pos[i];
|
||||
}
|
||||
cout << endl;
|
||||
cin >> total;
|
||||
}
|
||||
|
||||
auto sfirstclose = [&]() {
|
||||
int low = 2;
|
||||
int high = n;
|
||||
int ans = 2;
|
||||
while (low <= high) {
|
||||
int mid = (low + high) >> 1;
|
||||
|
||||
cout << "? " << mid;
|
||||
rep(i, mid) {
|
||||
cout << ' ' << pos[i];
|
||||
}
|
||||
cout << endl;
|
||||
int cur;
|
||||
cin >> cur;
|
||||
|
||||
if (cur == total) {
|
||||
ans = mid;
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
low = mid + 1;
|
||||
}
|
||||
|
||||
return ans;
|
||||
};
|
||||
|
||||
int c = sfirstclose();
|
||||
|
||||
int v = pos[c - 1];
|
||||
for (int i = 0; i + 1 < n; i += 2) {
|
||||
cout << "? 9 " << i + 1 << ' ' << v << ' ' << v << ' ' << i + 2 << ' ' << v << ' ' << i + 1 << ' ' << i + 1 << ' ' << i + 2 << ' ' << i + 2 << endl;
|
||||
int cur;
|
||||
cin >> cur;
|
||||
|
||||
char a1[] = {')', ')', '(', '('};
|
||||
char a2[] = {')', '(', '(', ')'};
|
||||
|
||||
ans[i] = a1[cur];
|
||||
ans[i + 1] = a2[cur];
|
||||
}
|
||||
|
||||
if (n & 1) {
|
||||
cout << "? 2 " << n << ' ' << pos[c - 1] << endl;
|
||||
int cur;
|
||||
cin >> cur;
|
||||
|
||||
if (cur == 1) {
|
||||
ans.back() = '(';
|
||||
} else {
|
||||
ans.back() = ')';
|
||||
}
|
||||
}
|
||||
|
||||
cout << "! " << ans << endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
223
Codeforces Round 265 (Div. 1)/B. Restore Cube.cpp
Normal file
223
Codeforces Round 265 (Div. 1)/B. Restore Cube.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
/* Problem URL: https://codeforces.com/contest/464/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;
|
||||
|
||||
struct pt {
|
||||
ll x, y, z;
|
||||
|
||||
pt(ll x, ll y, ll z): x(x), y(y), z(z) {}
|
||||
pt() = default;
|
||||
|
||||
friend istream &operator >> (istream &is, pt &a) {
|
||||
is >> a.x >> a.y >> a.z;
|
||||
return is;
|
||||
}
|
||||
|
||||
friend ostream &operator << (ostream &os, pt a) {
|
||||
os << a.x << ' ' << a.y << ' ' << a.z;
|
||||
return os;
|
||||
}
|
||||
|
||||
pt operator ^ (pt b) {
|
||||
return pt(y * b.z- z * b.y, z * b.x - x * b.z, x * b.y - y * b.x);
|
||||
}
|
||||
|
||||
ll operator * (pt b) {
|
||||
return x * b.x + y * b.y + z * b.z;
|
||||
}
|
||||
|
||||
pt operator - (pt b) {
|
||||
return pt(x - b.x, y - b.y, z - b.z);
|
||||
}
|
||||
|
||||
bool operator == (pt b) {
|
||||
return x == b.x && y == b.y && z == b.z;
|
||||
}
|
||||
|
||||
bool operator < (pt b) {
|
||||
if (x == b.x) {
|
||||
if (y == b.y) {
|
||||
return z < b.z;
|
||||
}
|
||||
return y < b.y;
|
||||
}
|
||||
return x < b.x;
|
||||
}
|
||||
};
|
||||
|
||||
ll dis2(pt a, pt b)
|
||||
{
|
||||
ll x = a.x - b.x;
|
||||
ll y = a.y - b.y;
|
||||
ll z = a.z - b.z;
|
||||
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
void pre()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#define TEST 0
|
||||
|
||||
void solve()
|
||||
{
|
||||
vvi pts(8, vi(3));
|
||||
cin >> pts;
|
||||
|
||||
rep(i, 8) {
|
||||
sortv(pts[i]);
|
||||
}
|
||||
|
||||
auto check = [&](){
|
||||
V<pt> p(8);
|
||||
rep(i, 8) {
|
||||
p[i] = {pts[i][0], pts[i][1], pts[i][2]};
|
||||
}
|
||||
|
||||
sortv(p);
|
||||
p.erase(unique(all(p)), p.end());
|
||||
|
||||
if (p.size() != 8) {
|
||||
return false;
|
||||
}
|
||||
|
||||
vi dis(7);
|
||||
nrep(i, 1, 8) {
|
||||
dis[i - 1] = dis2(p[i], p[0]);
|
||||
}
|
||||
|
||||
sortv(dis);
|
||||
|
||||
nrep(i, 1, 8) {
|
||||
vi d2;
|
||||
rep(j, 8) {
|
||||
if (i == j) {
|
||||
continue;
|
||||
}
|
||||
|
||||
d2.push_back(dis2(p[i], p[j]));
|
||||
}
|
||||
|
||||
sortv(d2);
|
||||
if (d2 != dis) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
function<bool(int)> func = [&](int i){
|
||||
if (i >= 8) {
|
||||
return check();
|
||||
}
|
||||
|
||||
do {
|
||||
if (func(i + 1)) {
|
||||
return true;
|
||||
}
|
||||
} while (next_permutation(all(pts[i])));
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!func(0)) {
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "YES\n";
|
||||
cout << pts;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
182
Codeforces Round 874 (Div. 3)/G. Ksyusha and Chinchilla.cpp
Normal file
182
Codeforces Round 874 (Div. 3)/G. Ksyusha and Chinchilla.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1833/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;
|
||||
cin >> n;
|
||||
|
||||
V<set<pair<int, int>>> graph(n);
|
||||
|
||||
nrep(i, 1, n) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
a--, b--;
|
||||
graph[a].emplace(b, i);
|
||||
graph[b].emplace(a, i);
|
||||
}
|
||||
|
||||
set<int> er;
|
||||
|
||||
bool pos = true;
|
||||
function<int(int, int)> dfs = [&](int i, int p) {
|
||||
int c = 0;
|
||||
auto cur = graph[i].begin();
|
||||
while (cur != graph[i].end()) {
|
||||
auto [j, ind] = *cur;
|
||||
graph[i].erase({j, ind});
|
||||
cur = graph[i].begin();
|
||||
|
||||
if (graph[j].size() != 1) {
|
||||
graph[j].erase({i, ind});
|
||||
int res = dfs(j, ind);
|
||||
if (res == 0) {
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (res == 1) {
|
||||
if (c != 0) {
|
||||
pos = false;
|
||||
return 2;
|
||||
}
|
||||
|
||||
for (auto [k, _] : graph[i]) {
|
||||
er.insert(_);
|
||||
graph[k].erase({i, _});
|
||||
if (dfs(k, _) != 2) {
|
||||
pos = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
er.insert(ind);
|
||||
continue;
|
||||
}
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
if (c > 2) {
|
||||
pos = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return c;
|
||||
};
|
||||
|
||||
if (dfs(0, -1) != 2 || !pos) {
|
||||
cout << "-1\n";
|
||||
return;
|
||||
}
|
||||
|
||||
er.erase(0);
|
||||
|
||||
cout << er.size() << '\n';
|
||||
repv(i, er) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
159
Codeforces Round 877 (Div. 2)/C. No Prime Differences.cpp
Normal file
159
Codeforces Round 877 (Div. 2)/C. No Prime Differences.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1838/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;
|
||||
|
||||
constexpr int MAXN = 1e6 + 10;
|
||||
bool prime[MAXN];
|
||||
|
||||
void pre()
|
||||
{
|
||||
fill(prime, prime + MAXN, true);
|
||||
prime[1] = false;
|
||||
|
||||
nrep(i, 2, MAXN) {
|
||||
if (!prime[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = i * 2; j < MAXN; j += i) {
|
||||
prime[j] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define TEST 1
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vvi ans(n, vi(m));
|
||||
|
||||
if (!prime[m]) {
|
||||
rep(i, n) {
|
||||
rep(j, m) {
|
||||
ans[i][j] = i * m + j + 1;
|
||||
}
|
||||
}
|
||||
cout << ans << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!prime[n]) {
|
||||
rep(j, m) {
|
||||
rep(i, n) {
|
||||
ans[i][j] = j * n + i + 1;
|
||||
}
|
||||
}
|
||||
cout << ans << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
int cur = 1;
|
||||
for (int i = 0; i < n; i += 2) {
|
||||
rep(j, m) {
|
||||
ans[i][j] = cur;
|
||||
cur++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < n; i += 2) {
|
||||
rep(j, m) {
|
||||
ans[i][j] = cur;
|
||||
cur++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
141
Codeforces Round 901 (Div. 2)/D. Jellyfish and Mex.cpp
Normal file
141
Codeforces Round 901 (Div. 2)/D. Jellyfish and Mex.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1875/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;
|
||||
cin >> n;
|
||||
|
||||
vl a(n);
|
||||
cin >> a;
|
||||
|
||||
vi c(n + 3);
|
||||
repv(i, a) {
|
||||
if (i > n + 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
c[i]++;
|
||||
}
|
||||
|
||||
int mex = 0;
|
||||
|
||||
rep(i, n) {
|
||||
if (c[i] == 0) {
|
||||
mex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ll ans = OO;
|
||||
|
||||
vl dp(mex + 1, OO);
|
||||
dp[mex] = 0;
|
||||
|
||||
for (int i = n; i >= 0; i--) {
|
||||
nrep(j, i + 1, mex + 1) {
|
||||
rmin(dp[i], dp[j] + (c[i] - 1) * j + i);
|
||||
}
|
||||
}
|
||||
|
||||
cout << dp[0] << '\n';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1931/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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
priority_queue<int> a;
|
||||
int total = 0;
|
||||
rep(i, n) {
|
||||
string s;
|
||||
cin >> s;
|
||||
total += s.size();
|
||||
int rem = 0;
|
||||
while (s.back() == '0') {
|
||||
s.pop_back();
|
||||
rem++;
|
||||
}
|
||||
a.push(rem);
|
||||
}
|
||||
|
||||
while (!a.empty()) {
|
||||
int cur = a.top();
|
||||
a.pop();
|
||||
a.push(0);
|
||||
a.pop();
|
||||
total -= cur;
|
||||
}
|
||||
|
||||
cout << (total > m ? "Sasha\n" : "Anna\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
210
Codeforces Round 925 (Div. 3)/F. Chat Screenshots.cpp
Normal file
210
Codeforces Round 925 (Div. 3)/F. Chat Screenshots.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1931/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, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vvi p(k, vi(n));
|
||||
cin >> p;
|
||||
|
||||
if (n == 1 || k == 1) {
|
||||
cout << "YES\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (k == 2) {
|
||||
int i1 = 1;
|
||||
int i2 = 1;
|
||||
|
||||
rep(i, n) {
|
||||
if (i1 >= n) {
|
||||
if (p[1][i2] != p[0][0]) {
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i2 >= n) {
|
||||
if (p[0][i1] != p[1][0]) {
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p[0][i1] == p[1][i2]) {
|
||||
i1++;
|
||||
i2++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p[0][i1] == p[1][0]) {
|
||||
i1++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p[1][i2] == p[0][0]) {
|
||||
i2++;
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "YES\n";
|
||||
return;
|
||||
}
|
||||
|
||||
V<bool> vis(n + 1);
|
||||
int cur = -1;
|
||||
|
||||
int next = -1;
|
||||
|
||||
int eq = n;
|
||||
|
||||
nrep(i, 1, n) {
|
||||
if (next == -1) {
|
||||
if (p[0][i] == p[1][i] || p[0][i] == p[2][i]) {
|
||||
cur = p[0][i];
|
||||
} else if (p[1][i] == p[2][i]) {
|
||||
cur = p[1][i];
|
||||
} else {
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
cur = next;
|
||||
}
|
||||
|
||||
next = -1;
|
||||
vis[cur] = true;
|
||||
rep(j, k) {
|
||||
if (p[j][i] != cur) {
|
||||
if (!vis[p[j][0]]) {
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (next != -1 && p[j][i] != next) {
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
|
||||
next = p[j][i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vis[p[j][0]]) {
|
||||
cout << "NO\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "YES\n";
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
170
Codeforces Round 927 (Div. 3)/D. Card Game.cpp
Normal file
170
Codeforces Round 927 (Div. 3)/D. Card Game.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1932/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;
|
||||
cin >> n;
|
||||
|
||||
char t;
|
||||
cin >> t;
|
||||
|
||||
V<string> tmp;
|
||||
V<string> ev;
|
||||
rep(i, n << 1) {
|
||||
string a;
|
||||
cin >> a;
|
||||
|
||||
if (a[1] == t) {
|
||||
ev.emplace_back(a);
|
||||
continue;
|
||||
}
|
||||
tmp.emplace_back(a);
|
||||
}
|
||||
|
||||
sort(all(ev), greater<>());
|
||||
sort(all(tmp), greater<>());
|
||||
|
||||
repv(i, tmp) {
|
||||
ev.emplace_back(i);
|
||||
}
|
||||
|
||||
V<bool> vis(n);
|
||||
V<pair<int, int>> ans;
|
||||
|
||||
function<bool(int)> func = [&](int i) {
|
||||
if (i >= (n << 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (vis[i]) {
|
||||
return func(i + 1);
|
||||
}
|
||||
|
||||
nrep(j, i + 1, (n << 1)) {
|
||||
if (vis[j]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ev[i][1] == t && ev[j][1] != t) || (ev[i][1] == ev[j][1] && ev[i][0] > ev[j][0])) {
|
||||
vis[j] = true;
|
||||
ans.emplace_back(j, i);
|
||||
if (func(i + 1)) {
|
||||
return true;
|
||||
}
|
||||
vis[j] = false;
|
||||
ans.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!func(0)) {
|
||||
cout << "IMPOSSIBLE\n";
|
||||
return;
|
||||
}
|
||||
|
||||
repv(i, ans) {
|
||||
cout << ev[i.first] << ' ' << ev[i.second] << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
140
Codeforces Round 931 (Div. 2)/C. Find a Mine.cpp
Normal file
140
Codeforces Round 931 (Div. 2)/C. Find a Mine.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1934/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()
|
||||
{
|
||||
ll n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
auto ask = [&](int x, int y) {
|
||||
if (y <= 0) {
|
||||
return 100LL;
|
||||
}
|
||||
cout << "? " << x << ' ' << y << endl;
|
||||
ll ans;
|
||||
cin >> ans;
|
||||
return ans;
|
||||
};
|
||||
|
||||
auto answer = [&](int x, int y) {
|
||||
cout << "! " << x << ' ' << y << endl;
|
||||
};
|
||||
|
||||
ll dis1 = ask(1, 1);
|
||||
ll dis2 = ask(n, 1);
|
||||
|
||||
ll y = (dis1 + dis2 - n + 3) >> 1;
|
||||
ll x = dis1 + 2 - y;
|
||||
|
||||
ll tmp = ask(x, y);
|
||||
if (tmp == 0) {
|
||||
answer(x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
dis2 = ask(1, m);
|
||||
|
||||
x = (dis1 + dis2 - m + 3) >> 1;
|
||||
y = dis1 + 2 - x;
|
||||
|
||||
answer(x, y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
139
Codeforces Round 944 (Div. 4)/F. Circle Perimeter.cpp
Normal file
139
Codeforces Round 944 (Div. 4)/F. Circle Perimeter.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1971/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()
|
||||
{
|
||||
ll r;
|
||||
cin >> r;
|
||||
|
||||
ll low = r * r;
|
||||
ll high = (r + 1) * (r + 1);
|
||||
|
||||
ll x = 0;
|
||||
ll y = 0;
|
||||
|
||||
auto dis = [&](ll x, ll y) {
|
||||
return x * x + y * y;
|
||||
};
|
||||
|
||||
ll ans = 0;
|
||||
|
||||
while (y <= r) {
|
||||
while (dis(x + 1, y) <= low) {
|
||||
x++;
|
||||
}
|
||||
|
||||
while (dis(x, y) >= high) {
|
||||
x--;
|
||||
}
|
||||
|
||||
while (dis(x - 1, y) >= low && x > 0) {
|
||||
ans++;
|
||||
x--;
|
||||
}
|
||||
|
||||
ans++;
|
||||
y++;
|
||||
}
|
||||
|
||||
cout << ans + (ans - 2) * 3 + 2 << '\n';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/1923/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, q;
|
||||
cin >> n >> q;
|
||||
|
||||
vl a(n);
|
||||
cin >> a;
|
||||
|
||||
vi pref(n + 1);
|
||||
vl sum(n + 1);
|
||||
|
||||
nrep(i, 1, n + 1) {
|
||||
pref[i] = pref[i - 1] + (a[i - 1] == 1);
|
||||
sum[i] += sum[i - 1] + (a[i - 1] - 1) * (a[i - 1] != 1);
|
||||
}
|
||||
|
||||
while (q--) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
|
||||
if (l == r || (sum[r] - sum[l - 1] < pref[r] - pref[l - 1])) {
|
||||
cout << "NO\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "YES\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/2004/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;
|
||||
|
||||
int ac[256];
|
||||
ac['R'] = 1;
|
||||
ac['B'] = 2;
|
||||
ac['G'] = 4;
|
||||
ac['Y'] = 8;
|
||||
|
||||
vi mask(n);
|
||||
|
||||
vvi adj(16);
|
||||
|
||||
rep(i, n) {
|
||||
string a;
|
||||
cin >> a;
|
||||
|
||||
mask[i] = ac[a[0]] | ac[a[1]];
|
||||
adj[mask[i]].push_back(i);
|
||||
}
|
||||
|
||||
rep(i, 16) {
|
||||
sortv(adj[i]);
|
||||
}
|
||||
|
||||
while (q--) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
a--, b--;
|
||||
|
||||
if (mask[a] & mask[b]) {
|
||||
cout << abs(a - b) << '\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
int ans = oo;
|
||||
int f = min(a, b);
|
||||
|
||||
rep(i, 16) {
|
||||
if (__builtin_popcount(i) != 2 || (i & mask[a]) == 0 || (i & mask[b]) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto itr = upper_bound(all(adj[i]), f);
|
||||
if (itr != adj[i].end()) {
|
||||
rmin(ans, abs(*itr - a) + abs(*itr - b));
|
||||
}
|
||||
|
||||
if (itr != adj[i].begin()) {
|
||||
itr--;
|
||||
rmin(ans, abs(*itr - a) + abs(*itr - b));
|
||||
}
|
||||
}
|
||||
|
||||
cout << (ans == oo ? -1 : ans) << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
156
Good Bye 2017/C. New Year and Curling.cpp
Normal file
156
Good Bye 2017/C. New Year and Curling.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/* Problem URL: https://codeforces.com/contest/908/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;
|
||||
}
|
||||
|
||||
using ld = long double;
|
||||
|
||||
const int oo = INT32_MAX >> 1;
|
||||
const ll OO = INT64_MAX >> 1;
|
||||
|
||||
const ld EPS = 1e-9;
|
||||
|
||||
struct pt {
|
||||
ld x, y;
|
||||
|
||||
pt(ld x, ld y): x(x), y(y) {}
|
||||
pt() = default;
|
||||
|
||||
friend istream &operator >> (istream &is, pt &a) {
|
||||
is >> a.x >> a.y;
|
||||
return is;
|
||||
}
|
||||
|
||||
friend ostream &operator << (ostream &os, pt a) {
|
||||
os << a.x << a.y;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
void pre()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#define TEST 0
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n;
|
||||
int rad;
|
||||
cin >> n >> rad;
|
||||
|
||||
V<pt> ans;
|
||||
|
||||
ld x;
|
||||
cin >> x;
|
||||
ans.emplace_back(pt(x, rad));
|
||||
|
||||
rep(i, n - 1) {
|
||||
cin >> x;
|
||||
|
||||
ld l = x - rad * 2;
|
||||
ld r = x + rad * 2;
|
||||
|
||||
ld y = rad;
|
||||
|
||||
repv(now, ans) {
|
||||
if (now.x >= l && now.x <= r) {
|
||||
rmax(y, now.y + sqrtl(4 * rad * rad - abs(now.x - x) * abs(now.x - x)));
|
||||
}
|
||||
}
|
||||
|
||||
ans.emplace_back(x, y);
|
||||
}
|
||||
|
||||
repv(i, ans) {
|
||||
cout << setprecision(12) << i.y << ' ';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
pre();
|
||||
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,10 @@ A little collection of interesting problems that I randomly decided to do.
|
||||
- [B. Jzzhu and Sequences](https://codeforces.com/contest/450/problem/B)
|
||||
|
||||
Basic problem about matrix exponentation, but not as obvious.
|
||||
|
||||
- [D. Jellyfish and Mex](https://codeforces.com/problemset/problem/1875/D)
|
||||
|
||||
An interesting problem to thinkm about.
|
||||
|
||||
## Graph
|
||||
|
||||
|
||||
Reference in New Issue
Block a user