All problems were developed by me Supermagzzz and Stepavly.
Author: MikeMirzayanov
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int test = 1; test <= t; test++) {
string b;
cin >> b;
string a = b.substr(0, 2);
for (int i = 3; i < b.size(); i += 2) {
a += b[i];
}
cout << a << endl;
}
return 0;
}
Авторы: Supermagzzz, Stepavly
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
void solve() {
int n;
cin >> n;
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x % 2 != i % 2) {
if (i % 2 == 0) {
a++;
} else {
b++;
}
}
}
if (a != b) {
cout << -1 << endl;
} else {
cout << a << endl;
}
}
int main() {
int n;
cin >> n;
while (n--) {
solve();
}
}
Авторы: Supermagzzz, Stepavly
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int test = 1; test <= t; test++) {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int res = 0;
for (int i = 0; i < n;) {
int j = i + 1;
for (; j < n && s[j] != '1'; j++);
int left = s[i] == '1' ? k : 0;
int right = j < n && s[j] == '1' ? k : 0;
int len = j - i;
if (left == k) {
len--;
}
len -= left + right;
if (len > 0) {
res += (len + k) / (k + 1);
}
i = j;
}
cout << res << endl;
}
return 0;
}
1367D - Задача на доске Автор: MikeMirzayanov
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
int main() {
int q;
cin >> q;
forn(qq, q) {
string s;
cin >> s;
int n;
cin >> n;
vector<int> b(n);
forn(i, n)
cin >> b[i];
vector<vector<int>> groups;
while (true) {
vector<int> pos;
forn(i, n)
if (b[i] == 0)
pos.push_back(i);
if (pos.empty())
break;
groups.push_back(pos);
forn(i, n)
if (b[i] == 0)
b[i] = INT_MAX;
else
for (int pp: pos)
b[i] -= abs(i - pp);
}
map<char, int> cnts;
forn(i, s.size())
cnts[s[i]]++;
auto j = cnts.rbegin();
string t(n, '?');
for (auto g: groups) {
while (j->second < g.size())
j++;
for (int pp: g)
t[pp] = j->first;
j++;
}
cout << t << endl;
}
}
Автор: MikeMirzayanov
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
cin >> test;
while (test--) {
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> cnt(26);
for (char c : s) {
cnt[c - 'a']++;
}
for (int len = n; len >= 1; len--) {
vector<bool> used(len);
vector<int> cycles;
for (int i = 0; i < len; i++) {
if (used[i]) {
continue;
}
int j = (i + k) % len;
used[i] = true;
cycles.push_back(0);
cycles.back()++;
while (!used[j]) {
cycles.back()++;
used[j] = true;
j = (j + k) % len;
}
}
vector<int> cur_cnt(cnt);
sort(cycles.begin(), cycles.end());
sort(cur_cnt.begin(), cur_cnt.end());
bool can_fill = true;
while (!cycles.empty()) {
if (cur_cnt.back() < cycles.back()) {
can_fill = false;
break;
} else {
cur_cnt.back() -= cycles.back();
cycles.pop_back();
sort(cur_cnt.begin(), cur_cnt.end());
}
}
if (can_fill) {
cout << len << endl;
break;
}
}
}
}
1367F2 - Летающая сортировка (сложная версия)
Автор: MikeMirzayanov Stepavly Supermagzzz
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> v(n);
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
a[i] = {v[i], i};
}
sort(a.begin(), a.end());
vector<int> p(n);
int j = 0;
unordered_multiset<int> next;
for (int i = 0; i < n; i++) {
if (i > 0 && a[i].first != a[i - 1].first) {
j++;
}
p[a[i].second] = j;
next.insert(j);
}
unordered_map<int, int> d;
vector<int> dp1(n), dp2(n), dp3(n), cnt(n);
for (int i = 0; i < n; i++) {
if (next.count(p[i])) {
next.erase(next.find(p[i]));
}
if (d.count(p[i] - 1)) {
if (!d.count(p[i])) {
dp2[i] = max(dp2[i], dp1[d[p[i] - 1]] + 1);
if (!next.count(p[i] - 1)) {
dp2[i] = max(dp2[i], dp2[d[p[i] - 1]] + 1);
}
}
if (!next.count(p[i] - 1)) {
dp3[i] = max(dp3[i], dp2[d[p[i] - 1]] + 1);
}
dp3[i] = max(dp3[i], dp1[d[p[i] - 1]] + 1);
}
if (d.count(p[i])) {
dp3[i] = max(dp3[i], dp3[d[p[i]]] + 1);
dp2[i] = max(dp2[i], dp2[d[p[i]]] + 1);
dp1[i] = dp1[d[p[i]]] + 1;
} else {
dp1[i] = 1;
}
dp2[i] = max(dp2[i], dp1[i]);
dp3[i] = max(dp3[i], dp2[i]);
d[p[i]] = i;
}
cout << n - *max_element(dp3.begin(), dp3.end()) << "\n";
}
int main() {
int n;
cin >> n;
while (n--) {
solve();
}
}