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 - Task On The Board Авторы: 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 cnt = 0;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
cnt++;
n /= i;
}
}
cnt += n != 1;
cout << cnt << endl;
}
int main() {
int n;
cin >> n;
while (n--) {
solve();
}
}
Автор: 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 - Flying Sort (Hard Version)
Автор: 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;
for (int i = 0; i < n; i++) {
if (i > 0 && a[i].first != a[i - 1].first) {
j++;
}
p[a[i].second] = j;
}
map<int, int> d;
vector<int> dp(n), cnt(n);
for (int i = 0; i < n; i++) {
int ans1 = 0, ans2 = 0;
if (d.count(p[i] - 1)) {
ans1 = dp[d[p[i] - 1]];
}
if (d.count(p[i])) {
ans2 = dp[d[p[i]]];
}
dp[i] = max(ans1, ans2) + 1;
d[p[i]] = i;
}
cout << n - *max_element(dp.begin(), dp.end()) << "\n";
}
int main() {
int n;
cin >> n;
while (n--) {
solve();
}
}