### vovuh's blog

By vovuh, history, 2 months ago,

1454A - Special Permutation

Idea: MikeMirzayanov

Tutorial
Solution

1454B - Unique Bid Auction

Idea: MikeMirzayanov

Tutorial
Solution

1454C - Sequence Transformation

Idea: MikeMirzayanov

Tutorial
Solution

1454D - Number into Sequence

Idea: MikeMirzayanov

Tutorial
Solution

1454E - Number of Simple Paths

Idea: vovuh

Tutorial
Solution

1454F - Array Partition

Idea: MikeMirzayanov

Tutorial
Solution
Solution (Gassa)

• +134

By vovuh, history, 2 months ago, translation,

Hello! Codeforces Round #686 (Div. 3) will start at Nov/24/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

UPD: I would also like to thank Ivan Gassa Kazmenko for invaluable help with the round preparation!

UPD2: Editorial is published!

• +402

By vovuh, history, 3 months ago,

I'm really sorry about issues with problems E and F. Can't say anything more because I don't want to justify my mistakes.

1433A - Boring Apartments

Idea: vovuh

Tutorial
Solution

1433B - Yet Another Bookshelf

Idea: vovuh

Tutorial
Solution

1433C - Dominant Piranha

Idea: vovuh

Tutorial
Solution

1433D - Districts Connection

Idea: MikeMirzayanov

Tutorial
Solution

1433E - Two Round Dances

Idea: MikeMirzayanov

Tutorial
Solution

1433F - Zero Remainder Sum

Idea: MikeMirzayanov

Tutorial
Solution

1433G - Reducing Delivery Cost

Idea: MikeMirzayanov

Tutorial
Solution

• +115

By vovuh, history, 3 months ago,

Alright, I'm done. I wanted to write a blog like that for a long time, but now I really don't have enough patience to ignore this issue anymore. I want to say that I get 100-200 clarifications each Div.3 round. It doesn't even matter how well the statements are, it doesn't matter if there are any issues with solutions or checkers, people always find what to ask.

Before I start whining here, I really want to recommend anyone to read these two Um_nik blogs: this one and this one. Sorry, Um_nik, I unnecessarily tagged you, I will not do that anymore.

Now some breaking news for most participants: your local IDE compiler and Codeforces compiler are actually different things! If your code works fine locally but gets WA/TL/RE/ML/etc on Codeforces, it (most probably) means you have a bug somewhere in your code. There are rare cases when the issue is with compiler differences, but these cases are really rare. If you have such issue, what do you think you have to do? Of course write a question about that! I got like 50 questions like this on today's contest. It's hilarious. I really suggest you to run your code in custom invocation tab instead of writing a question. If you run your code on Codeforces, you will get the output as it is here and, probably, you will understand what is wrong with your solution.

Also, I got a lot of questions about the problem 1433F - Zero Remainder Sum . Many people were confused if the whole sum you get should be divisible by $k$ or the sum of each row should be divisible by $k$. The thing I want to recommend here: read Um_nik blogs. Whoops, unnecessary tag, sorry. To be fair, you could maybe... probably... at least read and understand the first example and the Note about that (the matrix of size $3 \times 4$, $12$ elements, come on, it is not hard). If you read that, you will understand that the whole sum should be divisible by $k$, because otherwise the example answer is wrong. There were no sentences showing that you should consider the divisibility of each row. I make Notes section exactly for such cases (when something can be misleading or unclear). I'm also trying to make examples as clear as possible, to try to cover every possible case that can confuse anyone (this problem was not an exception).

The thing about clarifications that really makes me burn: why do you think that your question should be answered immediately after you send it? The answer time here is not more than $5$ minutes usually. I heard that the answer time on other platforms can be much and much more than here. Also, please, take in consideration that Codeforces is a huge platform and there are almost 17 thousands participants in the today's round. 17 thousands people versus me and sometimes, maybe, MikeMirzayanov, BledDest or someone else who helps me with questions. When you are spamming something like "why my question is not answered?? please answer!!" you are just increasing the amount of work for me and the waiting time for others. I always answer all questions, you just need to be a bit patient.

About the problem 1433E - Two Round Dances. Yeah, the statement of this problem was really misleading and didn't match the examples, and I'm really sorry about that. We added this problem like $2-3$ hours before the round start just to smooth out the difficulty curve. This is pretty old problem that was already partially prepared. I read the statement, wrote the solution and it matched my understanding of the problem. I wanted to write proving naive solution a bit later, but I had too many things to correct in other problems' statements, so I completely forgot to do that. Sorry for that issue, this was my fault.

Continuing the previous paragraph, I want to mention two people (without their handles, it will be obvious to them even without direct mentioning): one guy wrote that "this round is complete disaster make it unrated". I opened his submissions list and saw he solved only A and B. The only thing that could make this round unrated is the wrong statement of E. He didn't even solve C and D. I asked him if the issue with E really affected him when he didn't solve easier problems, but got no answer. The other guy was really rude, and he flamed so much. As the last question from him, I got "what the hell is this there is no mention of rotation in the question. do you realize that?? give you handle i will talk to u later" (this is a citation). I'm really sad about that. I don't understand why some people think they can just talk like that to others.

Some things about previous rounds: one day, I got so many questions if the round is rated or not during the time we were figuring out if we really have to make it unrated. I got something like $50$ questions about this and just answered "read the global announcement". $50$ times. I wasted like $5$ minutes to answer all such questions instead of answering the real ones.

About English: so many questions have pretty strange English and I just can't understand what are you trying to say/ask. Please, try to make your question as clear as possible, because if you just write some sequence of words and send it to me, I will answer "question in unclear" (after spending like $30$ seconds trying to understand that) and will wait for the real question instead of the sequence of words without meaning.

And, in conclusion, I want to recommend you: read Um_nik blogs (whoops). He did really great work about how to read and not to read problem statements. These blogs are a high quality source of understanding how to read and understand statements. Please, read the statement, read the Note, try to figure out the answer on the example, read the global announcement before asking the question. Much question answers can be retrieved from these things. I'm exhausted because of answering questions that are answered in the problem itself (the great example is today's problem C. I got like $10-20$ questions like "can there be several answers???" but it was bolded in the statement).

I'm done. Thank you for reading if you had patience to read all my whining. Feel free to blame me or something like that, I understand that I'm not perfect and make a lot of mistakes.

• +979

By vovuh, history, 3 months ago, translation,

Hello! Codeforces Round #677 (Div. 3) will start at Oct/20/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

UPD: Thanks to infinitepro, nuipojaluista, MrReDoX and Peinot for testing the round and giving the feedback about the problems!

UPD2: Editorial is published!

• +271

By vovuh, history, 4 months ago,

1426A - Floor Number

Idea: fcspartakm

Tutorial
Solution

1426B - Symmetric Matrix

Idea: BledDest

Tutorial
Solution

1426C - Increase and Copy

Idea: vovuh

Tutorial
Solution
Solution 2

1426D - Non-zero Segments

Idea: BledDest

Tutorial
Solution

1426E - Rock, Paper, Scissors

Idea: fcspartakm

Tutorial
Solution

1426F - Number of Subsequences

Idea: fcspartakm

Tutorial
Solution

• +102

By vovuh, history, 4 months ago,

Notice the unusual start time.

Hello!

Codeforces Round #674 (Div. 3) will start at Sep/28/2020 11:05 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

This round consists mostly of the problems of the first stage of All-Russian Olympiad of School Students in Saratov and will be hosted during the real competition time. The problems were invented and prepared by Ivan BledDest Androsov, Alexander fcspartakm Frolov and me.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

UPD: Thanks to Ivan MrReDoX Ushakov, Ivan Ivan19981305 Georgiev and Dmitry nuipojaluista Kadomtsev for testing the round!

UPD2: Editorial is published!

• +258

By vovuh, history, 5 months ago,

I'm so thankful to all testers, especially to Gassa and Rox for their invaluable help!

1409A - Yet Another Two Integers Problem

Idea: vovuh

Tutorial
Solution

1409B - Minimum Product

Idea: vovuh

Tutorial
Solution

1409C - Yet Another Array Restoration

Idea: vovuh

Tutorial
Solution (Gassa)
Solution (vovuh)
Solution (Rox)

1409D - Decrease the Sum of Digits

Idea: MikeMirzayanov

Tutorial
Solution

1409E - Two Platforms

Idea: vovuh

Tutorial
Solution

1409F - Subsequences of Length Two

Idea: vovuh

Tutorial
Solution
Solution (Gassa, greedy, O(n^4))

• +107

By vovuh, history, 5 months ago, translation,

Hello! Codeforces Round #667 (Div. 3) will start at Sep/04/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

UPD: Huge thanks to Ivan Gassa Kazmenko for testing the round and fixing some issues with statements and the round in general! Also thanks to nuipojaluista, kocko, Ilya-bar and infinitepro for testing the round!

UPD2: Editorial is published!

• +365

By vovuh, history, 6 months ago,

All ideas belong to MikeMirzayanov.

1399A - Remove Smallest

Tutorial
Solution

Tutorial
Solution

1399C - Boats Competition

Tutorial
Solution

1399D - Binary String To Subsequences

Tutorial
Solution

1399E1 - Weights Division (easy version)

Tutorial
Solution

1399E2 - Weights Division (hard version)

Tutorial
Solution

1399F - Yet Another Segments Subset

Tutorial
Solution

• +124

By vovuh, history, 6 months ago, translation,

Hello! Codeforces Round #661 (Div. 3) will start at Aug/05/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

UPD: Huge thanks to Ivan Gassa Kazmenko for testing the round and fixing some issues with statements and the round in general!

UPD2: Editorial is published!

• +424

By vovuh, history, 6 months ago,

All ideas belong to MikeMirzayanov.

1385A - Three Pairwise Maximums

Tutorial
Solution

1385B - Restore the Permutation by Merger

Tutorial
Solution

1385C - Make It Good

Tutorial
Solution

1385D - a-Good String

Tutorial
Solution

1385E - Directing Edges

Tutorial
Solution

1385F - Removing Leaves

Tutorial
Solution

1385G - Columns Swaps

Tutorial
Solution

• +157

By vovuh, history, 6 months ago, translation,

Hello! Codeforces Round #656 (Div. 3) will start at Jul/17/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

UPD: Also thanks to infinitepro for help with statements and testing the round!

UPD2: Editorial is published!

• +511

By vovuh, history, 7 months ago,

1374A - Required Remainder

Idea: vovuh

Tutorial
Solution

1374B - Multiply by 2, divide by 6

Idea: vovuh

Tutorial
Solution

1374C - Move Brackets

Idea: MikeMirzayanov

Tutorial
Solution

1374D - Zero Remainder Array

Idea: vovuh

Tutorial
Solution

1374E1 - Reading Books (easy version)

Idea: MikeMirzayanov

Tutorial
Solution

1374E2 - Reading Books (hard version)

Idea: MikeMirzayanov

Tutorial
Solution

1374F - Cyclic Shifts Sorting

Idea: MikeMirzayanov

Tutorial
Solution

• +92

By vovuh, history, 7 months ago, translation,

<almost-copy-pasted-part>

Hello! Codeforces Round #653 (Div. 3) will start at Jun/28/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

</almost-copy-pasted-part>

UPD: Also thanks to ma_da_fa_ka for testing the round and special thanks to Dmitrii _overrated_ Umnov, Artem Rox Plotkin and, of course, Mike MikeMirzayanov Mirzayanov for discussing ideas and great help with round preparaion!

UPD2: Editorial is published!

• +450

By vovuh, history, 8 months ago,

All problems, except the problem D, are mine. The problem D author is MikeMirzayanov.

1353A - Most Unstable Array

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
cout << min(2, n - 1) * m << endl;
}

return 0;
}


1353B - Two Arrays And Swaps

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &it : a) cin >> it;
vector<int> b(n);
for (auto &it : b) cin >> it;
sort(a.begin(), a.end());
sort(b.rbegin(), b.rend());
int ans = 0;
for (int i = 0; i < n; ++i) {
if (i < k) ans += max(a[i], b[i]);
else ans += a[i];
}
cout << ans << endl;
}

return 0;
}


1353C - Board Moves

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long ans = 0;
for (int i = 1; i <= n / 2; ++i) {
ans += i * 1ll * i;
}
cout << ans * 8 << endl;
}

return 0;
}


1353D - Constructing the Array

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

struct cmp {
bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
int lena = a.second - a.first + 1;
int lenb = b.second - b.first + 1;
if (lena == lenb) return a.first < b.first;
return lena > lenb;
}
};

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n;
cin >> n;
set<pair<int, int>, cmp> segs;
segs.insert({0, n - 1});
vector<int> a(n);
for (int i = 1; i <= n; ++i) {
pair<int, int> cur = *segs.begin();
segs.erase(segs.begin());
int id = (cur.first + cur.second) / 2;
a[id] = i;
if (cur.first < id) segs.insert({cur.first, id - 1});
if (id < cur.second) segs.insert({id + 1, cur.second});
}
for (auto it : a) cout << it << " ";
cout << endl;
}

return 0;
}


1353E - K-periodic Garland

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

auto solve = [](const string &s) {
int n = s.size();
int all = count(s.begin(), s.end(), '1');
int ans = all;
vector<int> res(n);
int pref = 0;
for (int i = 0; i < n; ++i) {
int cur = (s[i] == '1');
pref += cur;
res[i] = 1 - cur;
if (i > 0) res[i] += min(res[i - 1], pref - cur);
ans = min(ans, res[i] + all - pref);
}
return ans;
};

int t;
cin >> t;
while (t--) {
int n, k;
string s;
cin >> n >> k >> s;
vector<string> val(k);
int cnt = count(s.begin(), s.end(), '1');
for (int i = 0; i < n; ++i) {
val[i % k] += s[i];
}
int ans = 1e9;
for (auto &it : val) ans = min(ans, solve(it) + (cnt - count(it.begin(), it.end(), '1')));
cout << ans << endl;
}

return 0;
}


1353F - Decreasing Heights

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); ++i)

const long long INF64 = 1e18;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<long long>> a(n, vector<long long>(m));
forn(i, n) forn(j, m) {
cin >> a[i][j];
}
long long a00 = a[0][0];
long long ans = INF64;
forn(x, n) forn(y, m) {
long long need = a[x][y] - x - y;
if (need > a00) continue;
a[0][0] = need;
vector<vector<long long>> dp(n, vector<long long>(m, INF64));
dp[0][0] = a00 - need;
forn(i, n) forn(j, m) {
long long need = a[0][0] + i + j;
if (need > a[i][j]) continue;
if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i][j] - need);
if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + a[i][j] - need);
}
ans = min(ans, dp[n - 1][m - 1]);
}
cout << ans << endl;
}

return 0;
}


• +150

By vovuh, history, 9 months ago,

<almost-copy-pasted-part>

Hello! Codeforces Round #642 (Div. 3) will start at May/14/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

</almost-copy-pasted-part>

UPD: Thanks to ma_da_fa_ka, Jaydeep999997, abhishek_saini, infinitepro and socho for testing the round!

UPD2: Editorial is published!

• +397

By vovuh, history, 9 months ago,

All problem ideas belong to MikeMirzayanov. And he prepared all problems himself. I just helped with testing, reviewing and tutorial writing.

1352A - Сумма круглых чисел

Tutorial
Solution

1352B - Сумма слагаемых одинаковой четности

Tutorial
Solution

1352C - K-е неделящееся на n

Tutorial
Solution

1352D - Алиса, Боб и конфеты

Tutorial
Solution in O(n)
Solution in O(n^2)

1352E - Особые элементы

Tutorial
Solution

1352F - Восстановление 01-строки

Tutorial
Solution

1352G - Особая перестановка

Tutorial
Solution

• +133

By vovuh, history, 9 months ago,

1343A - Candies

Idea: vovuh

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int pw = 2; pw < 30; ++pw) {
int val = (1 << pw) - 1;
if (n % val == 0) {
cerr << val << endl;
cout << n / val << endl;
break;
}
}
}

return 0;
}


1343B - Balanced Array

Idea: vovuh

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n;
cin >> n;
n /= 2;
if (n & 1) {
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
for (int i = 1; i <= n; ++i) {
cout << i * 2 << " ";
}
for (int i = 1; i < n; ++i) {
cout << i * 2 - 1 << " ";
}
cout << 3 * n - 1 << endl;
}

return 0;
}


1343C - Alternating Subsequence

Idea: vovuh and MikeMirzayanov

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

auto sgn = [&](int x) {
if (x > 0) return 1;
else return -1;
};

int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (auto &it : a) cin >> it;
long long sum = 0;
for (int i = 0; i < n; ++i) {
int cur = a[i];
int j = i;
while (j < n && sgn(a[i]) == sgn(a[j])) {
cur = max(cur, a[j]);
++j;
}
sum += cur;
i = j - 1;
}
cout << sum << endl;
}

return 0;
}


1343D - Constant Palindrome Sum

Idea: MikeMirzayanov

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &it : a) cin >> it;
vector<int> cnt(2 * k + 1);
for (int i = 0; i < n / 2; ++i) {
++cnt[a[i] + a[n - i - 1]];
}
vector<int> pref(2 * k + 2);
for (int i = 0; i < n / 2; ++i) {
int l1 = 1 + a[i], r1 = k + a[i];
int l2 = 1 + a[n - i - 1], r2 = k + a[n - i - 1];
assert(max(l1, l2) <= min(r1, r2));
++pref[min(l1, l2)];
--pref[max(r1, r2) + 1];
}
for (int i = 1; i <= 2 * k + 1; ++i) {
pref[i] += pref[i - 1];
}
int ans = 1e9;
for (int sum = 2; sum <= 2 * k; ++sum) {
ans = min(ans, (pref[sum] - cnt[sum]) + (n / 2 - pref[sum]) * 2);
}
cout << ans << endl;
}

return 0;
}


1343E - Weights Distributing

Idea: MikeMirzayanov

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;

vector<vector<int>> g;

void bfs(int s, vector<int> &d) {
d[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto to : g[v]) {
if (d[to] == INF) {
d[to] = d[v] + 1;
q.push(to);
}
}
}
}

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n, m, a, b, c;
cin >> n >> m >> a >> b >> c;
--a, --b, --c;

vector<int> p(m);
for (auto &it : p) cin >> it;
sort(p.begin(), p.end());
vector<long long> pref(m + 1);
for (int i = 0; i < m; ++i) {
pref[i + 1] = pref[i] + p[i];
}

g = vector<vector<int>>(n);
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
g[x].push_back(y);
g[y].push_back(x);
}

vector<int> da(n, INF), db(n, INF), dc(n, INF);
bfs(a, da);
bfs(b, db);
bfs(c, dc);

long long ans = 1e18;
for (int i = 0; i < n; ++i) {
if (da[i] + db[i] + dc[i] > m) continue;
ans = min(ans, pref[db[i]] + pref[da[i] + db[i] + dc[i]]);
}
cout << ans << endl;
}

return 0;
}


1343F - Restore the Permutation by Sorted Segments

Idea: MikeMirzayanov

Tutorial
Solution
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<set<int>> segs;
for (int i = 0; i < n - 1; ++i) {
set<int> cur;
int k;
cin >> k;
for (int j = 0; j < k; ++j) {
int x;
cin >> x;
cur.insert(x);
}
segs.push_back(cur);
}
for (int fst = 1; fst <= n; ++fst) {
vector<int> ans;
bool ok = true;
vector<set<int>> cur = segs;
for (auto &it : cur) if (it.count(fst)) it.erase(fst);
ans.push_back(fst);
for (int i = 1; i < n; ++i) {
int cnt1 = 0;
int nxt = -1;
for (auto  &it : cur) if (it.size() == 1) {
++cnt1;
nxt = *it.begin();
}
if (cnt1 != 1) {
ok = false;
break;
}
for (auto &it : cur) if (it.count(nxt)) it.erase(nxt);
ans.push_back(nxt);
}
if (ok) {
set<set<int>> all(segs.begin(), segs.end());
for (int i = 1; i < n; ++i) {
set<int> seg;
seg.insert(ans[i]);
bool found = false;
for (int j = i - 1; j >= 0; --j) {
seg.insert(ans[j]);
if (all.count(seg)) {
found = true;
all.erase(seg);
break;
}
}
if (!found) ok = false;
}
}
if (ok) {
for (auto it : ans) cout << it << " ";
cout << endl;
break;
}
}
}

return 0;
}


• +163

By vovuh, history, 9 months ago, translation,

<almost-copy-pasted-part>

Hello! Codeforces Round #636 (Div. 3) will start at Apr/21/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

</almost-copy-pasted-part>

UPD: Also thanks to Sakhiya07, infinitepro and ma_da_fa_ka for testing the round!

UPD2: Editorial is published!

• +297

By vovuh, history, 9 months ago,

1335A - Candies and Two Sisters

Idea: vovuh

Tutorial
Solution

1335B - Construct the String

Idea: MikeMirzayanov

Tutorial
Solution

1335C - Two Teams Composing

Idea: MikeMirzayanov

Tutorial
Solution

1335D - Anti-Sudoku

Idea: vovuh

Tutorial
Solution

1335E1 - Three Blocks Palindrome (easy version)

Idea: MikeMirzayanov

Tutorial
Solution

1335E2 - Three Blocks Palindrome (hard version)

Idea: MikeMirzayanov

Tutorial
Solution

1335F - Robots on a Grid

Idea: MikeMirzayanov

Tutorial
Solution
Solution (actually _overrated_, fastest O(nm log nm))

• +115

By vovuh, history, 10 months ago,

<almost-copy-pasted-part>

Hello! Codeforces Round #634 (Div. 3) will start at Apr/13/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

</almost-copy-pasted-part>

UPD: Also thanks to ma_da_fa_ka and infinitepro for testing the round!

UPD2: Editorial is published!

• +358

By vovuh, history, 10 months ago,

1328A - Divisibility Problem

Idea: MikeMirzayanov

Tutorial
Solution

1328B - K-th Beautiful String

Idea: MikeMirzayanov

Tutorial
Solution

1328C - Ternary XOR

Idea: vovuh

Tutorial
Solution

1328D - Carousel

Idea: MikeMirzayanov

Tutorial
Solution

1328E - Tree Queries

Idea: MikeMirzayanov and vovuh

Tutorial
Solution

1328F - Make k Equal

Idea: MikeMirzayanov

Tutorial
Solution

• +127

By vovuh, history, 10 months ago, translation,

<almost-copy-pasted-part>

Hello! Codeforces Round #629 (Div. 3) will start at Mar/26/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round.

Good luck!

</almost-copy-pasted-part>

Thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for help with testing the round!

UPD: Also thanks to Vitaliy kuviman Kudasov for testing the round!

UPD2: Editorial is published!

• +352

By vovuh, history, 11 months ago,

Suddendly, all ideas of this contest are mine. And I'm very sorry about one missing small test in the problem B. This is the biggest mistake I made during the preparation of this round.

1324A - Yet Another Tetris Problem

Tutorial
Solution

1324B - Yet Another Palindrome Problem

Tutorial
Solution

1324C - Frog Jumps

Tutorial
Solution

1324D - Pair of Topics

Tutorial
Solution

1324E - Sleeping Schedule

Tutorial
Solution

1324F - Maximum White Subtree

Tutorial
Solution

• +92