We know about FST and we are really, really sorry about it. Even though we still hope that you liked the problems.
A: Digit Minimization
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T --> 0) {
string n;
cin >> n;
if (n.size() == 2) {
cout << n[1] << '\n';
} else {
cout << *min_element(n.begin(), n.end()) << '\n';
}
}
return 0;
}
B: Z mod X = C
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, c;
cin >> a >> b >> c;
cout << a + b + c << " " << b + c << " " << c << "\n";
}
int main() {
int t;
cin >> t;
while (t--) solve();
return 0;
}
C: Column Swapping
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
void solve(vector<vector<int>> &a) {
int n = a.size(), m = a[0].size();
vector<int> bad;
for (int i = 0; i < n && bad.empty(); i++) {
vector<int> b = a[i];
sort(b.begin(), b.end());
for (int j = 0; j < m; j++) {
if (a[i][j] != b[j]) bad.push_back(j);
}
}
if ((int)bad.size() == 0) {
cout << 1 << " " << 1 << "\n";
return;
}
if ((int)bad.size() > 2) {
cout << -1 << "\n";
return;
}
for (int i = 0; i < n; i++) {
swap(a[i][bad[0]], a[i][bad[1]]);
}
for (int i = 0; i < n; i++) {
for (int j = 1; j < m; j++) {
if (a[i][j] < a[i][j - 1]) {
cout << -1 << "\n";
return;
}
}
}
cout << bad[0] + 1 << " " << bad[1] + 1 << "\n";
return;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
solve(a);
}
return 0;
}
D: Traps
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
void solve() {
int n, k;
cin >> n >> k;
long long ans = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
ans += a[i];
a[i] += i + 1;
}
sort(all(a));
reverse(all(a));
for (int i = 0; i < k; i++) ans -= a[i];
for (int i = 0; i < k; i++) {
ans += n;
ans -= i;
}
cout << ans << "\n";
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
int t;
cin >> t;
while (t--) solve();
return 0;
}
E: MEX vs DIFF
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define pii pair<int, int>
#define puu pair<unsigned, unsigned>
#define ll long long
#define mp make_pair
#define ui unsigned
#define ull unsigned long long
#define ld double
#define pld pair<ld, ld>
#define pll pair<ll, ll>
const int INF = 1e9 + 1;
const ll INFLL = 1e18;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &c : a) cin >> c;
map<int, int> cnt;
for (auto &c : a) cnt[c]++;
set<pii> s1, s2;
int sum1 = 0;
for (auto &c : cnt) s2.insert(mp(c.se, c.fi));
int ans = INF;
int skip = 0;
for (int x = 0; x <= n; x++) {
if (s1.find(mp(cnt[x - 1], x - 1)) != s1.end()) {
sum1 -= cnt[x - 1];
s1.erase(mp(cnt[x - 1], x - 1));
}
if (s2.find(mp(cnt[x - 1], x - 1)) != s2.end()) {
s2.erase(mp(cnt[x - 1], x - 1));
}
while (s2.size() && sum1 + s2.begin()->fi <= k) {
s1.insert(*s2.begin());
sum1 += s2.begin()->fi;
s2.erase(s2.begin());
}
if (k < skip) break;
int now = x + s2.size();
if (x == 0) {
now = max(1, (int)s2.size());
}
ans = min(ans, now - x);
if (cnt[x] == 0) skip++;
}
cout << ans << "\n";
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
int t;
cin >> t;
while (t--) solve();
return 0;
}
F: Diverse Segments
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define pii pair<int, int>
#define puu pair<unsigned, unsigned>
#define ll long long
#define mp make_pair
#define ui unsigned
#define ull unsigned long long
#define ld double
#define pld pair<ld, ld>
#define pll pair<ll, ll>
const int INF = 1e9 + 1;
const ll INFLL = 1e18;
vector<int> f;
void incr(int x, int d) {
for (; x < (int)f.size(); x |= (x + 1)) f[x] = max(f[x], d);
}
int get(int x) {
int ans = -1;
for (; x >= 0; x = (x & (x + 1)) - 1) ans = max(ans, f[x]);
return ans;
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (auto &c : a) cin >> c;
map<int, vector<int>> gist;
for (int i = 0; i < n; i++) gist[a[i]].pb(i);
vector<pii> seg(m);
f.assign(n, -1);
for (auto &c : seg) {
cin >> c.fi >> c.se; c.fi--; c.se--;
incr(c.fi, c.se);
}
vector<int> mnl(n);
set<int> s;
int l = n;
for (int r = n - 1; r >= 0; r--) {
while (l - 1 >= 0 && !s.count(a[l - 1])) {
l--;
s.insert(a[l]);
}
mnl[r] = l;
s.erase(a[r]);
}
int mnr = -1;
for (auto &c : seg) {
int l = c.fi, r = c.se;
if (mnl[r] <= l) continue;
mnr = max(mnr, mnl[r] - 1);
}
if (mnr == -1) {
cout << 0 << "\n";
return;
}
int ans = mnr + 1;
for (int l = 0; l + 1 < n; l++) {
if (gist[a[l]][0] != l) {
int id = lower_bound(all(gist[a[l]]), l) - gist[a[l]].begin() - 1;
int pr = gist[a[l]][id];
if (get(pr) >= l) {
break;
}
}
int id = upper_bound(all(gist[a[l]]), mnr) - gist[a[l]].begin();
if (id != (int)gist[a[l]].size()) {
int nxt = gist[a[l]][id];
if (get(l) >= nxt) {
mnr = nxt;
}
}
mnr = max(mnr, l + 1);
ans = min(ans, mnr - l);
}
cout << ans << "\n";
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
int t;
cin >> t;
while (t--) solve();
return 0;
}
G: Euclid Guess
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define pii pair<int, int>
#define puu pair<unsigned, unsigned>
#define ll long long
#define mp make_pair
#define ui unsigned
#define ull unsigned long long
#define ld double
#define pld pair<ld, ld>
#define pll pair<ll, ll>
#define int ll
const int INF = 1e9 + 1;
const ll INFLL = 1e18;
vector<vector<int>> g;
vector<int> with;
vector<int> usd;
int dfs(int v) {
if (usd[v]) return 0;
usd[v] = 1;
for (auto &to : g[v]) {
if (with[to] == -1) {
with[to] = v;
return 1;
}
}
for (auto &to : g[v]) {
if (dfs(with[to])) {
with[to] = v;
return 1;
}
}
return 0;
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
int n, A;
cin >> n >> A;
vector<int> a(n);
vector<int> l, r;
for (auto &c : a) {
cin >> c;
if (3 * c > A) {
l.pb(c);
} else {
r.pb(c);
}
}
g.resize(l.size());
with.resize(r.size(), -1);
for (int i = 0; i < (int)l.size(); i++) {
for (int j = 0; j < (int)r.size(); j++) {
if (l[i] % r[j] == 0 && 2 * l[i] + r[j] <= A) {
g[i].pb(j);
}
}
}
int cnt = 0;
for (int i = 0; i < (int)l.size(); i++) {
usd.assign(l.size(), 0);
cnt += dfs(i);
}
if (cnt < (int)l.size()) {
cout << -1;
return 0;
}
vector<pii> ans;
for (int j = 0; j < (int)r.size(); j++) {
if (with[j] == -1) {
ans.pb(3 * r[j], 2 * r[j]);
} else {
ans.pb(2 * l[with[j]] + r[j], l[with[j]] + r[j]);
}
}
cout << ans.size() << "\n";
for (auto &c : ans) cout << c.fi << " " << c.se << "\n";
return 0;
}
H: Hard Cut
Editorial
Tutorial is loading...
Implementation
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
int g[MAXN + 1];
string s;
vector<pair<int, int>> segments; // [l, r]
int get(int k, int i) { // get k-th '1' on [i, |s|)
--i;
while (k --> 0) i = s.find('1', i + 1);
return i;
}
void five() {
int first = get(1, 0), last = get(5, 0);
int r = (int)s.size() - 1;
if (last - first + 1 == 5) { // creating 16: ['001111', '1', '0000']
segments.emplace_back(0, last - 1);
segments.emplace_back(last, last);
if (last < r) segments.emplace_back(last + 1, r);
} else { // creating 8: cut out '101' or '100' and cut everything in single digits
int pos = s.find("101");
if (pos == string::npos) pos = s.find("100");
for (int i = 0; i < pos; ++i) segments.emplace_back(i, i);
segments.emplace_back(pos, pos + 2);
for (int i = pos + 3; i <= r; ++i) segments.emplace_back(i, i);
}
}
void solve(int l, int r, int k, int n) { // [l; r]
if (k == n) { // cutting into single digits
for (int i = l; i <= r; ++i) segments.emplace_back(i, i);
} else if (k == 2 && n == 3) {
int pos = get(1, l);
if (s[pos + 1] == '1') { // ['11', '00...00']
segments.emplace_back(l, pos + 1);
if (pos + 2 <= r) segments.emplace_back(pos + 2, r);
} else { // ['10', '0001', '00000']
int newpos = get(1, pos + 1);
segments.emplace_back(l, pos + 1);
segments.emplace_back(pos + 2, newpos);
if (newpos + 1 <= r) segments.emplace_back(newpos + 1, r);
}
} else if (3 * k / 2 >= n) { // using previous if technique
int pos = get(2, l);
solve(l, pos, 2, 3);
if (k > 2) solve(pos + 1, r, k - 2, n - 3);
} else if ((k == 4 && n == 8) || (k == 9 && n == 16)) {
int pos = get(1, l);
string sub = s.substr(pos, 3);
segments.emplace_back(l, pos + 2);
if (sub == "100") solve(pos + 3, r, k - 1, n - 4);
if (sub == "101") solve(pos + 3, r, k - 2, n - 5);
if (sub == "110") solve(pos + 3, r, k - 2, n - 6);
if (sub == "111") solve(pos + 3, r, k - 3, n - 7);
} else if ((k == 7 && n == 11) || (k == 10 && n == 16)) {
int mid = get(4, l);
solve(l, mid, 4, 8);
solve(mid + 1, r, k - 4, n - 8);
} else { // common case
int mid = get(k / 2, l);
solve(l, mid, k / 2, n / 2);
solve(mid + 1, r, k - k / 2, n / 2);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
g[1] = 1;
for (int i = 2; i <= MAXN; ++i) g[i] = g[(i + 1) / 2] * 2;
int T;
cin >> T;
while (T --> 0) {
cin >> s;
int k = count(s.begin(), s.end(), '1');
if (!k) {
cout << -1 << '\n';
continue;
}
segments.clear();
if (k == 5) five();
else solve(0, (int)s.size() - 1, k, g[k]);
cout << segments.size() << '\n';
for (auto &[l, r] : segments) {
cout << l + 1 << ' ' << r + 1 << '\n';
}
}
return 0;
}
Weak pretest C...
Good F though i didn't solve it in time:)
Neither did I.qwq
But really like the problems like F.
very good round! especially pretest for C! THANK YOU!!!!!!!!!!!!
pretest for D are also very good!!!!!! the best round of this year
pretest for B are brilliant too
Did you prove your solution?
i don't have time to prove my solutions on the contest. it's better to get a WA than lose a lot of time
then it's your problem that your solition failed system testing, not authors. if we did have very very strong pretests, some problems could be solved by just guessing the solution which is bad for me
well, if someone tries to guess the solutions, he gets a huge penalty. Also it's possible to guess the answer only in div2 A, so the pretest for other tasks should be strong
ok, your opinion is not bad too, but that's codeforces and if your solution passed pretests, it doesn't mean that it will past system testing
I proved my solution and it worked as charm if elements were distinct, I didn't consider when elements are equal.
very good round! especially pretest for C! THANK YOU!!!!!!!!!!!!
Passed pretests for C, but failed in system test. Please make the pretests stronger
for C, how can we load so many elements into a matrix if the size of the matrix is 10 ^ 5 x 10 ^ 5 ??
It's guaranteed that the sum of n*m over all test cases does not exceed 2*(10^5).
It does say that the sum of $$$n \times m$$$ is less or equal to $$$2\times 10^5$$$
In the statement it says that $$$n \cdot m \leq 2 \text{e}5$$$. So the total number of matrix entries is at most $$$200 000$$$.
The size of the matrix is not 10^10 it is 10^5 , you can read the constraints again, so the entire matrix has 10^5 elements in total . so ya this number is doable . Happens.
I got WA on test 12 in C, and so many people also getting this, can anybody tell me why this happened? Thank You :)
This test case will give -1 for all(mostly) those who got WA
if you found anywhere that previous element in column is greater than next one then you have to check totally left and totally right untill you didn't get their exact position and then store them like this 1 4 3 3 3 3 or this 1 4 4 4 4 3 .
Can somebody mention test case 12 of problem C?
I believe this one
1 3
2 2 1
Input 1 1 7 1 2 4 3 3 3 5 Jury's answer 3 6
how?
I think ans is -1
Edit -> sorry my bad, I read the input wrong
Please add tutorials for other problems too!
downvote
very good c pretest, very challenging pretest, LOVE IT
I solved problem D without realising the fact that we should always use all $$$k$$$ jumps, here is my approach:
Let $$$b_i$$$ denote the reduction in the damage you can get by jumping over the $$$i$$$-th mine. Initially, $$$b_i = a_i - (n - i)$$$ as the $$$n - i$$$ mines after $$$i$$$ each gain an extra point of damage.
Now notice how the array $$$b$$$ changes after we jump over a mine, say at position $$$j$$$. For $$$i<j$$$, $$$b_i$$$ would increase by $$$1$$$ as there is one less mine affected by the additional damage. For $$$i>j$$$, $$$b_i$$$ would also increase by $$$1$$$ as the additional damage from jumping over $$$j$$$ can be skipped as well.
Therefore we can show that the relative ordering of values in $$$b$$$ never changes, and we can do a simple greedy, taking the maximum $$$b_i$$$ each step.
damn, i had that idea, but i thought that I should only do that when a_i — (n — i) > 0
used the same approach
I set the condition for 3 incorrect positions in C, but there was WA 2 xd, I had to remove it and got OK/ 157699542 and 157709794 UPD i do not check other data in test :((
Problem G's tests were not very good: 157719356
im sorry daddy :(
XD
Great round, why do you downvote??? I understand that this round has weak pretests, but problems weren't bad
Is there a distinct border between "weak pretests" and intention to increase hacks amount?
I guess people are salty after getting FST's.
$$$Concise$$$ tasks! The main thing was the idea, not the knowledge of a well-known complex algorithm.
P.S. I almost solved D using logic as in editorial, but also used a segment tree for.. who knows. Got WA. Removed segment tree — got AC :D (Always important to prove solution first)
Tell me please where I am wrong In A if we have a 3 digits number like 312, the answer should be 2, because there is no way that Alice can play, so that she gets 1. What is wrong with that logic?
swap (3, 2) -> 21 -> swap(2, 1) -> 1
Logic for $$$n > 3$$$: move mimimum digit to $$$2nd$$$ position and don't touch until last Alice step. Then swap with $$$1st$$$ and done.
is there any idea for solving D using binary search ?
No, it could make sense if not all of $$$k$$$ jumps could be used for some reason, but here it is proved that we should use all of them, so solution is greedy.
Maybe some of the problems are one of the best in 2022 (as one of the testers said). But problem C is one of the worst this year (problem on its own + pretests). So sad pretests were bad for this round.
The worst pretests EVER.
Some hacks in problem E returning unexpected verdict?
How to fix WA5 in F? My solution
Failing testcase: Ticket 7278
Thank you. I already realized that my solution is not correct.
Still couldn't understand problem D . I got the part why we need to use all k jumps but why pickih the k maximal values of ai — (n — i) would work ? Can someone explain .
Me too. Someone, please explain D.
for each place i the damage you can potentially dodge is
a_i + pre_i — r_i
where pre_i is the number of jumps before i, r_i is the number of mines after i.
Now you want to maximize the sum
sum(a_i + pre_i — r_i)
(a_i — r_i) is fixed for each i so doesn't really change. And let's look at sum(pre_i)
Since we HAVE TO use K jumps (as said in the tutorial and also you said you understood), then let's suppose they are on a straight line
[o, o, o, x, o, o, x, o, o, x...]
x is a jump. Now no matter where x is, for the first x, there's 0 jump before it. For the second x, there's 1 x before it etc. Hence the sum really is just
sum(a_i — r_i) — K*(K-1)/2
hope this helps
nice, great, awesome, incredible, unbelievable, insane, amazing, astounding, astonishing pretests for C.
Weak pretest C... Many top coders did mistakes in a hurry but at least that test case should be in the pretest. 1 FST can ruin a full contest.
Can somebody write the editorial on "How to understand this editorial !!"
In addition to weak pretests in C and D, it is also bad TESTS in G. Look at this submission. This is the most simple greedy solution, which should not pass the test, but it did.
This is my approach for problem D - Let's say you can jump only once. Then our main aim is to find the index jumping over which gives us minimum total damage. Consider two indices i, j such that i < j. If we see, either we jump at element at index i or index j, it will add same answer (n — j) to subarray [j+1, n]. So, main concern is subarray [i, j]. Now, if we remove i, then total damage for this subarray will be a[i+1] + a[i+2] ...... + a[j] + (j — i). If we remove j , then total damage for subarray [i, j] = a[i] + a[i+1] + ..... + a[j-1].
On subtracting first equation from second we get a[i] — a[j] — (j — i). So, if it's better to remove j in optimal solution then above written expression should be less than equal to 0 i.e. a[i] — a[j] — (j — i) <= 0 which implies a[i] + i <= a[j] + j. So, here we seen for two indices. Similarly can be proved for other indices as well. So, sort given elements according to a[i] + i and jump over maximum k elements sorted according to a[i] + i.
Now that's a nice solution.
https://mirror.codeforces.com/contest/1684/submission/157737407 What is wrong with my submission?
idk but unfortunately it's bad to use conditional like this
else if(ind.size() > 2){ cout<<-1<<endl; return; }
( u already check in !is_sorted ) or swap in this task. I had the same problemWhen you return if
m == 1
, you do not read somea
values, and next iteration of solver reads them instead of newn
andm
.Weak pretests in C? That might be happened sometimes. The biggest problem is, if someone did not hacked main test 77 in problem D, many wrong solutions might get AC (and unwarranting scores).
In E there is the following funny solution — note that it is always advantageous to make such a change in which the mex increases. So, to find out the final mex, you can simply do a binary search.
And if we know the final mex, then we must delete all the elements of the not less mex in order of increasing the number of occurrences in the array.
You can find the final MEX without using binary search. Just try to fill in the holes starting from 0 and stop when the number of holes gets higher than k. (Submission)
Hey, Have you read the editorial of task $$$E$$$.
If yes? In the author's implementation, in the current iteration wherein we are assuming the $$$mex$$$ to be $$$i$$$, where do we ensure that $$$i$$$ is not present in the set $$$s2$$$? I mean, where do we ensure that $$$i$$$ is surely getting picked up and replaced with some other non-negative integer. If $$$i$$$ is not removed, then the $$$mex$$$ is definitely not $$$i$$$, won't it affect the final $$$ans$$$?
For first, i write this before editorial, for second, you can no tnihg in this solution and implementation it turns out to be very simple without places where you can make a mistake)
I guess we cannot ensure i is not in s2. But this will not affect the answer: if mex is something larger, then currently we over-estimated the cost and later when we enumerate to the actual value of mex we will get the corresponding true cost.
Weak pretest in B -_-
I agree
I think that pretest is made to not make a load of testing when the round is running... so the pretests must be so strong, so when someone get pretests passed, his probability to get accept should be 95% or above, because when I got WA on pretests I could modify my code and submit it again and got accepted, but after the round has finished and got WA or TLE in the tests after pretests I can't do anything in that time....
So the pretest should contains all tricky tests and corner tests and TLE tests.
+1
Since there is no editorial for problem E could somebody give me a brief explanation of his idea please?
Contest was great, one of the most enjoyable for me. Weak pretests ≠ bad contest.
In Editorial for problem A maximum is written instead of minimum
Good problems but weak pretests. Oh well...
There is a person who is inexplicably similar to my code. I think it may be that someone in my room maliciously distributed my code. Unfortunately, I have no evidence
too much weak pretest for problem C ;)
wow very original problem H!!!!!
https://artofproblemsolving.com/community/c6h1472066p8547136
My solution ideas for E, G, since there is no tutorial for E and G, yet.
The MEX of n elements must be in the range [0,n], so I will try each of them as MEX. For MEX = m, the array must have all elements from 0 till (m-1) and we do not care about any element >= m.
Thus, first I will check if it possible to make MEX = m, for this, the number of elements in the range [0,m-1] that are not in the array must be <= k. (We will take k bigger elements and "fill the gaps"). Then to make distinct elements minimum, I will take elements >= m, and convert them to 0, but which elements should I take? Those with minimum frequency (simple greedy logic). So I need to find the maximum number of elements >= m, such that the sum of their frequencies is <= k. This can be done using some data structures. (I myself used OrderedSet and Segment Tree). I leave this part as an exercise to the reader.
Finally, we know the MEX = m, and we can find the number of distinct elements as well, just take minimum now.
Simple case, if any value is smaller than (m/3), then it is easy, just make a pair {2x,3x}, in first step it'll give x, then nothing else. Another simple case, if any value is greater than m/2, it is impossible. (Prove how!)
So now, we only worry about elements in the range [m/3,m/2]. Consider such an element X. The pair {P,Q} which gives X, MUST be of the form {X+a,2*X+a} where a < X. Let's see why...
P and Q must be greater than X. If P % Q = X, then P = nQ + X, since Q > X, n must be = 1, because 2Q + X > 3X > m. Thus, P = Q + X. So the pair is of form, {Q+X,Q}. We know that Q < 2X, otherwise X+Q would be at least 3X which is > m. Let's say Q = X+a, since Q < 2X, thus, a < X.
So the pair is definitely of the form, {X+a,2*X+a}. In the next 2 steps, this will give us, X and a in the array. It is quite obvious that in the subsequent steps, we will end up with the GCD which will be a factor of X.
Now here's my point: all the numbers after X,a (such as X%a etc) will be "wasted" from the array, so instead of wasting all of them, we can just take the last one, because it will anyway be in that sequence. The last element will definitely be a factor of X and any factor of X works well for us.
So here's the solution, for all elements (X) greater than (m/3), we need to find a factor of those (a), and put pair {X+a, 2*X+a} in the answer. But a single "a" can be a factor of many X's. So we will use maximum bipartite matching here, to ensure that every "X" gets an "a".
Then for the remaining elements (y), just put the pair {2y,3y} in the answer.
E Code
G Code
(Sorry for not including formal proofs and latex, i find it easier to understand and explain intuitions)
For E: "and we do not care about any element >= m." Don't we also need to make sure that m should not be present for mex to be m? edit: is the reason that we can ignore this, the fact that, let's say when we fix mex = m, the actual mex was m+5, then we will get a strictly better answer when we fix the actual mex to be m+5?
Yes! Because, higher the MEX, better the answer would be, I also had the same confusion but it doesn't matter whether you remove elements equal to m or not.
The solution for E is different from mine, I used binary search (once again XD)
I'm just counting with inspect element, but in the top 2000 competitors, I ended up with 559 FSTs, a failure rate of 28%. Compare that with the last Div. 1 + 2 round, where I got 91 FSTs, or 4.5%, or the one before that with 76 FSTs, or ~4%. That's pretty absurd.
Secondly, let's say that we immediately get n−i damage if we jump over i-th trap. This way the first trap that we jump over will cause k−1 damage more than it should (because of k−1 traps that we jump over next), the second will cause k−2 damage more, ..., the last one will cause 0 damage more. So the total damage only increases by k(k−1)2 which does not depend on the traps that we choose. That's why the traps that we have to jump over in this problem are the same.
Can someone please explain what the author is trying to say here. I don't get how we get k-1 more damage if we do 1st jump, shouldn't it be n-i-(k-1). and similarly for 2nd jump n-i2-(k-2) and so on.
Edit: Figured it out.
My take on D.
We have to make K jumps, suppose we make them at indices (i1 , i2 , i3 .... ik) [0-indexed].
We see that the jumps will be more beneficial for us if we do them on traps which have higher a[i] + i value, as they give us better minimization of dmg. Thus the greedy approach :).
Edit:
isn't this possible that for some trap we might get a (save on damage) negative and then we should simply not jump that trap right so , why always do k jumps
jumping on a trap with negative (damage save) would be increasing damage.
because you jump at the end
In task B,I didn't read the statement correctly and took it as $$$ a < b < c \le 10^{18}$$$.
Is this task solvable then?
Have you read the intended solution? Why wouldn't it be solvable?
I mean that I wonder if it's solvable when $$$a<b<c \le 10^{18}$$$,bacause we have a limit of $$$x,y,z \le 10^{18}$$$.
Yes, it is. Try this, $$$x=a+b+c, y=b+c, z = c$$$
Nope, it is not. X must be greater than C and also fit in condition <= 10^18. It would not work for C=10^18
I developed a way to solve the task when $$$a<b<c\le10^{18}$$$ and $$$x,y,z \le 2 \times 10^{18}$$$.
And I'm curious if we can make the constraints a little smaller.
Anyone can explain F? I can’t get the idea from editorial. I tried to compute the shortest second occurrence of the same number for L and R, but not sure how to get minimum range.
I don't know a good place to say this or not but the 'You have to to do the following operation exactly once' should have been in bold letters in problem C.
H can be solved with dfs.
157757076
Can someone please help me understand why my solution for D is failing.
In D how is jumping over the first trap causing $$$k - 1 $$$ shouldn't it be $$$ n - 1 $$$? The first line of the second paragraph is literally that.
Not a very good way to give an editorial!
What's the problem with editorial?
I preferred the editorials better when there were hints given you know, those are great during up solving a contest. well everyone has their own taste so.
For D, I thought that it would be a good idea to check for all jumps $$$0 \leq x \leq k$$$ the minimal value of damage taken; since the problem said "no more than k jumps".
Let $$$sum = \sum_j a_j$$$ .
For 1 jump, the total damage taken is $$$sum + (n-k) - a_k$$$ where $$$k$$$ is the index that we jump over. $$$n-k$$$ is the bonus damage we will get from all further traps after $$$k$$$.
For 2 jumps, the total damage taken is $$$sum+(n-k_1-1)+(n-k_2)-(a_{k_1}+a_{k_2})$$$ where $$$k_i$$$ is the index of the $$$i^{th}$$$ jump. Note that $$$-1$$$ with $$$n-k_1$$$ is due to the fact that we jump over $$$k_2$$$ as well and so no bonus damage taken there. (I initially forgot this part and got a WA).
Generalising, for $$$x$$$ jumps, the total damage taken is $$$sum+x*n- \frac{x(x-1)}{2} - [{\sum^x_{i=1}} (a_{k_i} + k_i)]$$$. Here for calculating the $$$[{\sum^x_{i=1}} (a_{k_i} + k_i)]$$$ part, we sum $$$a_i + i$$$ for every $$$i$$$ and store it in a separate array (say b), and then pick the max $$$x$$$ elements from the array greedily. So on each increasing value of $$$x$$$, we subtract the $$$b[n-x]$$$ value and recalculate the damage the this stage.
I tried to understand official editorial for 2 days. Yours I understood instantly, thank you sir.
https://mirror.codeforces.com/contest/1684/submission/157771378 i have checked so many cases but still not able to find the mistake please can anyone help in finding the mistake in this or which case i am missing
thank u so much
In editorial of D, it is said that we must choose k maximal values. But if a[i] — (n-i) happens to be negative (but still coming in k maximal), why to take it. It will increase the cost rather than saving.
Notice that first value to remove can never be negative(you can always remove last element in A without penalty), also notice that removing ANY element from A(and related value from B) is increasing left values in B by 1(values from left in A do not add extra penalty 1 for already removed element from right, values from right in A increase their value by 1 from already removed element from left)
how to handle the case when we use less than k jumps in problem d; cause in editorial we always consider k jumps exactly
Its always optimal to use all the k jumps. Reason for this is clearly mentioned in editorial:
it is always better to use all k jumps. If we jumped over less than k traps then we can jump over the last trap and the total damage will be less
Try reading it properly.
nice editorial explanation
Can anyone help me understand the solution for problem F in the editorial?
I have understood the entire logic, but facing some problems with the part where we have to calculate
j
. The editorial says the following:This j could be found, for example, by binary search in cnt array. To check whether two elements are in the same segments it is possible to use a segment tree or a Fenwick tree. It is possible to store for each i such maximal rj that there is a given segment [lj,rj] and lj≤i.
I am not sure what is
cnt
array and how we are using segment trees here.Minor nitpick: Editorial of A says: "Let $$$k$$$ be the length of $$$n$$$, [...] $$$k=1$$$ [...]" — but $$$n \geq 10$$$ according to the input constraints, so there is no case with $$$k=1$$$.
I passed B in 1.5 hours, hooray
What is meant by "FST"?
Failed System Tests
Does maximizing MEX (in problem E) always yield to the best answer? If it does, how to prove it?
Hint: diff — mex = count of unique numbers after mex
If you change a number to increase the MEX it will either won't change the answer or increase it, but never decrease it. So, maximing the MEX is a greedy choice
I solved D in the contest with that idea but I still feel something not correct, "we immediately get n−i damage if we jump over i-th trap" but I think it only correct if that is the last jump.. Sr for my bad english, hope you still able to understand what i mean
https://mirror.codeforces.com/contest/1684/submission/157771378 i have checked so many cases but still not able to find the mistake please can anyone help in finding the mistake in this or which case i am missing
"This way she can always get the maximal digit of n in the end of the game." maximal -> minimal
Why my C got WA on test 13: 157808169
Problem : 1684C
shishyando i think there is weak test case. case:
1
2 6
10 20 50 30 60 100
1 1 1 1 1 1
Correct ans : 3 4
please check this solution 157739326, get -1 but accepted.
Please also check the almost same two codes( 157871675 , 157866257 ). One is accepted, another is Wrong answer there is no solution.
In problem H there is an easier solution for $$$K>5$$$.
Just cut the number into single digits, and from left to right concatenate a number with the next digit, if the total sum does not exceed the next power of 2. I don't have proof, but probably it is just some case analysis.
If you think about this approach during the contest, how to realize that this approach is wrong when only sum=5?It is too difficult for me.
I upsolved the problem after the editorial. Also I did not know about the $$$K=5$$$ corner case: 111101 -> 11-11-01 is 7 with my construction.
Is there a way to come up with solution for problems like problem B. I solved it with Guessing.
Let's try to reduce our possible solutions, by assuming that $$$x > z$$$, which leads us to $$$z = c$$$ using the third expression. You could try and play with $$$x < z$$$, but it wouldn't help much. Also, $$$z = c$$$ only works because $$$b < c$$$, as $$$z$$$ needs to be greater than $$$b$$$ on the second expression.
Assuming that $$$z = c$$$, we are left with only two expressions:
Using equivalent expressions:
Applying the second expression on the first:
Now we need to find $$$k_1$$$ and $$$k_2$$$ that satisfies our initial assumption $$$x > z$$$, the simplest and most direct guess, which also leads to the editorial's solution: $$$k_1 = k_2 = 1$$$
Also, this only works because $$$a < b$$$, as $$$b+c$$$ needs to be greater than $$$a$$$ in the first expression.
Thank you
If you are/were getting a WA/RE verdict on problems from this contest, you can get the smallest possible counter example for your submission on cfstress.com. To do that, click on the relevant problem's link below, add your submission ID, and edit the table (or edit compressed parameters) to increase/decrease the constraints.
If you are not able to find a counter example even after changing the parameters, reply to this thread (only till the next 7 days), with links to your submission and ticket(s).
my submission. can you help with this. Thanks in advance.
For E can anybody give a real proof for why maximizing MEX is always the best?
Does anyone know WHY I got so many downvotes? I have seen similar insane and meaningless downvotes elsewhere on Codeforces so I already know this crazy atmosphere. But this is wrong. Stop doing your meaningless downvotes and in particular, downvoting my comments doesn’t increase your rating.
I might be a little late but you can think about it like this:
DIFF = MEX + unique numbers above MEX.
Notice that DIFF — MEX will not be below zero.
The max MEX we can achieve, call it M, means that there are k "holes" between [0, M — 1]. Let's try to put numbers in these k places. We want to use the numbers above MEX first so that we can minimize DIFF. Now let's see what happens when we take the MEX as M — 1. There might be k holes between [0, M — 2] or there might be k — 1 holes between [0, M — 2]. In either situation, though, as we go down 1, we may be adding to the unique numbers that are > M — 1. It isn't optimal to add to these numbers because, if we increase the amount of these numbers, we might not be able to remove as many with our operations. And surely we won't be able to remove more with our operations.
Ugly implementation problems
Wrote a blog for 1684D — Traps : https://blatherstrike.blogspot.com/2023/08/1684d-traps.html
I implemented a DP approach in D... but ended up getting WA on test 2. Can DP not solve D? and why?
here is my submission link -> https://mirror.codeforces.com/contest/1684/submission/248797672