| Predictor | A | B | C | D | E | F | G | H |
|---|---|---|---|---|---|---|---|---|
| Proof_by_QED | 800 | 800 | 800 | 1000 | 1200 | 1300 | 1600 | 1800 |
| Dominater069 | 800 | 800 | 800 | 900 | 1200 | 1200 | 1600 | 1600 |
| reirugan | 800 | 800 | 800 | 900 | 1500 | 1500 | 1700 | 1700 |
| macaquedev | 800 | 800 | 800 | 900 | 1600 | 900 | 1800 | — |
| Filikec | 800 | 800 | 800 | 900 | 1300 | 1500 | 1700 | 1800 |
| Edeeva | 800 | 800 | 800 | 1000 | 1300 | 1600 | 1700 | 1900 |
| yoru_sacri | 800 | 800 | 800 | 900 | 1400 | 1700 | 1900 | 1900 |
| kevlu8 | 800 | 800 | 800 | 900 | 1600 | 1400 | 1700 | — |
| AG-88301 | 800 | 800 | 800 | 800 | 1400 | 1500 | — | — |
| -firefly- | 800 | 800 | 800 | 1000 | 1300 | 1200 | 1800 | 2000 |
| SpyrosAliv | 800 | 800 | 800 | 1000 | 1200 | 3500 | 1900 | 2000 |
| temporary1 | 800 | 800 | 800 | 1000 | 1400 | 1500 | 1500 | 2000 |
Thanks to reirugan for helping write the editorials.
2094A - Trippi Troppi
Problem Credits: Proof_by_QED
This can be solved by printing the zero-th index of each string in sequence. For example, suppose your strings are $$$a$$$, $$$b$$$, and $$$c$$$. Then in C++, you can use cout << a[0] << b[0] << c[0] << '\n';, and similarly, in Python you can use print(a[0] + b[0] + c[0]). See your preferred language's syntax for how to obtain a given indexed character from a string.
t = int(input())
for _ in range(t):
inp = input()
for w in inp.split():
print(w[0],end="")
print()
2094B - Bobritto Bandito
Problem Credits: Proof_by_QED
What is the condition for $$$l'$$$ and $$$r'$$$ to be valid?
We must have $$$r' - l' = m$$$ and $$$l\leq l' \leq 0 \leq r'\leq r$$$.
The problem reduces to finding $$$l'$$$ and $$$r'$$$ such that $$$r' - l' = m$$$ and $$$l\leq l' \leq 0 \leq r'\leq r$$$. There are several different approaches; two are outlined below.
One approach which runs in $$$O(1)$$$ time is to case on whether $$$m\leq r$$$. If $$$m\leq r$$$, we can choose $$$l' = 0$$$ and $$$r' = m$$$, and then we see that $$$r' - l' = m - 0 = m$$$ and $$$l \leq 0 \leq 0 \leq m \leq r$$$ as desired. If $$$m \gt r$$$, we can choose $$$l' = r-m$$$ and $$$r' = r$$$, and then we see that $$$r' - l' = r - (r-m) = m$$$ and $$$l \leq r-m \leq 0 \leq r \leq r$$$, where $$$l \leq r-m$$$ holds because $$$r-l = n \geq m$$$.
An alternative approach which runs in $$$O(m)$$$ time is to simply simulate the process; expand in an arbitrary direction which satisfies the desired inequalities until $$$r' - l' = m$$$.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m, l, r; cin >> n >> m >> l >> r;
int diff = n - m;
l = abs(l);
if (l >= diff) {
l -= diff;
diff = 0;
}
else {
diff -= l;
l = 0;
}
cout << -l << " " << r - diff << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
2094C - Brr Brrr Patapim
Problem Credits: cry
How can we find $$$p_i$$$ for $$$2\leq i\leq n$$$? How can we find $$$p_i$$$ for $$$n+1\leq i\leq 2n$$$?
For $$$2\leq i\leq n$$$, we can find $$$p_i$$$ by checking $$$G_{1, i-1}$$$. For $$$n+1\leq i\leq 2n$$$, we can find $$$p_i$$$ by checking $$$G_{n, i-n}$$$.
Observe that for all $$$2\leq i\leq n$$$, we can find $$$p_i$$$ by checking $$$G_{1, i-1}$$$. Then for all $$$n+1\leq i\leq 2n$$$, we can find $$$p_i$$$ by checking $$$G_{n, i-n}$$$. Now, we only have to find the value of $$$p_1$$$. However, each value from $$$1$$$ to $$$2n$$$ must appear exactly once in $$$p$$$. Thus, we can simply find the value which has not appeared yet, and choose that as $$$p_1$$$. This can be done by storing which values have been seen in a boolean array, and then finding which one remains false.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n; cin >> n;
vector<int> ans(2*n+1, 0);
vector<bool> used(2*n+1, false);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int x; cin >> x;
ans[i + j] = x;
used[x] = true;
}
}
for (int i = 1; i <= 2 * n; i++) {
if (ans[i] != 0) cout << ans[i] << " ";
else {
for (int j = 1; j <= n * 2; j++) {
if (!used[j]) {
used[j] = true;
cout << j << " ";
break;
}
}
}
}
cout << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
2094D - Tung Tung Sahur
Problem Credits: Proof_by_QED
What would happen if $$$s_1$$$ consists of only $$$L$$$?
In this case, the answer is yes if and only if $$$|s_1| \leq |s_2| \leq 2|s_1|$$$. Now try to generalize this.
First, let us consider a simpler case of the problem: suppose that there is only $$$L$$$ in both $$$s_1$$$ and $$$s_2$$$. Then it is clear that the answer is yes if and only if $$$|s_1| \leq |s_2| \leq 2|s_1|$$$. If this holds (in particular, we also necessitate that $$$s_1$$$ and $$$s_2$$$ consist of only a single character, and the same character), we will call $$$s_2$$$ an extension of $$$s_1$$$.
Now, observe that the problem given is simply the simpler version, repeated several times alternating between $$$L$$$ and $$$R$$$. So we can partition $$$s_1$$$ into "blocks" (where we define a block to be a maximal group of contiguous identical characters). Then the answer is yes if and only if $$$s_2$$$ is the concatenation of extensions of blocks in $$$s_1$$$. For example, consider $$$s_1 = LLLLLRL$$$. We see that this consists of five $$$L$$$s, one $$$R$$$, and one $$$L$$$. So the answer is yes if and only if $$$s_2$$$ consists of between five and ten $$$L$$$s (inclusive), between one and two $$$R$$$s, and between one and two $$$L$$$ 's, concatenated in that order.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
string a, b; cin >> a >> b;
int n = a.size();
int m = b.size();
if (m < n || m > 2 * n || a[0] != b[0]) {
cout << "NO\n";
return;
}
vector<int> aa, bb;
int cnt = 1;
for (int i = 1; i < n; i++) {
if (a[i] != a[i-1]) {
aa.push_back(cnt);
cnt = 1;
}
else cnt++;
}
aa.push_back(cnt);
cnt = 1;
for (int i = 1; i < m; i++) {
if (b[i] != b[i-1]) {
bb.push_back(cnt);
cnt = 1;
}
else cnt++;
}
bb.push_back(cnt);
if (aa.size() != bb.size()) {
cout << "NO\n";
return;
}
n = aa.size();
for (int i = 0; i < n; i++) {
if (aa[i] > bb[i] || aa[i] * 2 < bb[i]) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
2094E - Boneca Ambalabu
Problem Credits: Proof_by_QED
Consider each bit independently.
Suppose we fix $$$k$$$. How can we compute the desired sum quickly? Note that this may require preprocessing.
Here, it suffices to consider each bit independently, because addition is both commutative and associative. For $$$0\leq i \lt 30$$$, let $$$cnt_i$$$ denote the number of elements of $$$a$$$ which have the $$$i$$$-th bit set (where bits are indexed from the least significant bit being the $$$0$$$-th bit); note that these can be found in $$$O(30n)$$$ time (more generally, we need $$$O(\log\max{a_i})$$$ operations per element).
Now, suppose we choose a particular $$$k$$$. Then we can find the sum $$$(a_k\oplus a_1) + (a_k\oplus a_2) \dots + (a_k\oplus a_n)$$$ as follows: for a given bit position $$$i$$$, the number of elements $$$a_j$$$ such that $$$a_k \oplus a_j$$$ has the $$$i$$$-th bit set will be $$$cnt_i$$$ if the $$$i$$$-th bit of $$$a_k$$$ is not set, and $$$n-cnt_i$$$ if the $$$i$$$-th bit of $$$a_k$$$ is set. So we can simply add $$$cnt_i \cdot 2^i$$$ to our sum if the $$$i$$$-th bit of $$$a_k$$$ is not set, and add $$$(n-cnt_i) \cdot 2^i$$$ to our sum if the $$$i$$$-th bit of $$$a_k$$$ is set.
This allows us to compute $$$(a_k\oplus a_1) + (a_k\oplus a_2) \dots + (a_k\oplus a_n)$$$ for any $$$k$$$ in $$$O(30)$$$ time, so we can now compute this sum for all $$$k$$$ in $$$O(30n)$$$ time and output the maximum.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n; cin >> n;
int arr[n+1];
vector<int> cnt(30, 0);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
for (int j = 0; j < 30; j++) {
cnt[j] += ((arr[i] >> j) & 1);
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int tot = 0;
for (int j = 0; j < 30; j++) {
bool f = ((arr[i] >> j) & 1);
if (f) tot += (1 << j) * (n - cnt[j]);
else tot += (1 << j) * cnt[j];
}
ans = max(ans, tot);
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
2094F - Trulimero Trulicina
Problem Credits: Proof_by_QED
What would happen if we tried outputting the numbers $$$1, \dots, k, 1, \dots, k, \dots$$$ in the natural reading order? For example, for $$$n=3$$$, $$$m=4$$$, and $$$k=6$$$, we would output the following:
| 1 | 2 | 3 | 4 |
| 5 | 6 | 1 | 2 |
| 3 | 4 | 5 | 6 |
In which cases does this fail?
This fails if and only if $$$m$$$ is a multiple of $$$k$$$, because we see that horizontally adjacent elements differ by $$$1\pmod k$$$ and vertically adjacent elements differ by $$$m\pmod k$$$. Now try to resolve this case.
There are many working constructions for this problem; one of them is to case on whether or not $$$m$$$ is a multiple of $$$k$$$.
Suppose $$$m$$$ is not a multiple of $$$k$$$. For example, consider the second sample, where $$$n=3$$$, $$$m=4$$$, and $$$k=6$$$. Then we can output the numbers $$$1, \dots, k, 1, \dots, k, \dots$$$ in the natural reading order, as follows:
| 1 | 2 | 3 | 4 |
| 5 | 6 | 1 | 2 |
| 3 | 4 | 5 | 6 |
and we see that any two horizontally adjacent elements differ by $$$1\pmod k$$$, whereas any two vertically adjacent elements differ by $$$m\pmod k$$$, so no two adjacent elements are the same, as desired.
Now, suppose $$$m$$$ is a multiple of $$$k$$$. For example, consider the case $$$n=4$$$, $$$m=6$$$, and $$$k=3$$$. Suppose we were to try the above strategy, then we get:
| 1 | 2 | 3 | 1 | 2 | 3 |
| 1 | 2 | 3 | 1 | 2 | 3 |
| 1 | 2 | 3 | 1 | 2 | 3 |
| 1 | 2 | 3 | 1 | 2 | 3 |
which doesn't work, since vertically adjacent elements are the same. We can fix this by cyclically shifting every other row as follows:
| 1 | 2 | 3 | 1 | 2 | 3 |
| 2 | 3 | 1 | 2 | 3 | 1 |
| 1 | 2 | 3 | 1 | 2 | 3 |
| 2 | 3 | 1 | 2 | 3 | 1 |
and we see that any two horizontally adjacent elements differ by $$$1\pmod k$$$ as before, whereas any two vertically adjacent elements also differ by $$$1\pmod k$$$, so no two adjacent elements are the same, as desired.
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n,m,k = map(int,input().split())
LAST = [-1 for _ in range(m)]
for i in range(n):
shift = False
CUR = [0 for _ in range(m)]
for j in range(m):
elm = ((i * m + j) % k) + 1
if elm == LAST[j]:
shift = True
CUR[j] = elm
if shift:
CUR = [CUR[(j+1)%m] for j in range(m)]
print(*CUR)
LAST = CUR
2094G - Chimpanzini Bananini
Problem Credits: Proof_by_QED, cry
Note that reversing an array then pushing an element to the back is similar to simply pushing an element to the front. Thus, we would like to push elements to both ends of the array. What data structure supports this?
A deque is the most natural choice to use. Most languages, including C++, Java, and Python, include deques in their standard library, so you likely do not have to implement it yourself.
What other values do we need to maintain in order to keep track of score?
It suffices to keep track of the current score, the score of the array if it were backwards, the size of the array, and the sum of the array.
We can solve this using a deque. Let $$$score$$$ denote the current score, and $$$rscore$$$ denote the score of the array if it were backwards. Let $$$size$$$ denote the size of the array, and $$$sum$$$ denote the sum of the array. Then we consider how these three values change as each operation is performed.
Suppose operation 1 is performed. This is equivalent to popping the back element of the array and pushing it in the front. When you pop the back element of the array, $$$score$$$ decreases by $$$a_n \cdot size$$$. Then when you push it to the front, $$$score$$$ increases by $$$sum$$$ because $$$a_n$$$ is pushed to the first spot and every element from $$$a_1$$$ to $$$a_{n-1}$$$ moves forward one spot. Notice that $$$rscore$$$ changes in the reverse way; this is equivalent to popping the front element of the array and pushing it to the back. When you pop the front element of the array, $$$rscore$$$ decreases by $$$sum$$$, and when you push it to the back, $$$rscore$$$ increases by $$$a_n \cdot size$$$. Note that $$$size$$$ and $$$sum$$$ remain unchanged.
Suppose operation 2 is performed. Then we swap $$$score$$$ and $$$rscore$$$, and we also want to "reverse" the array. However, it is costly to entirely reverse the deque. Instead, we will set a flag to indicate that the array has been reversed (and similarly, if the flag is already set, we will unset it). If the flag is set, we simply switch the front and back ends whenever we access or modify the deque while performing operations 1 or 3.
Suppose operation 3 is performed. Then we see that $$$size$$$ increases by $$$1$$$ and $$$sum$$$ increases by $$$k$$$. Then $$$score$$$ increases by $$$k \cdot size$$$ and $$$rscore$$$ increases by $$$sum$$$ (using the new value of $$$sum$$$), by identical reasoning to that in operation 1.
Additional optimization: we don't actually have to maintain $$$rscore$$$; we can obtain it with the expression: $$$(n+1)\sum_{i=1}^na_i-score$$$. This is because $$$score + rscore = (n+1)\sum_{i=1}^na_i$$$ since the $$$i$$$-th term is counted $$$i$$$ times in $$$score$$$ and $$$n+1-i$$$ times in $$$rscore$$$.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int norm = 0, rev = 0;
int q; cin >> q;
int tot = 0;
int n = 0;
deque<int> qNorm, qRev;
int p = 0;
while (q--) {
int s; cin >> s;
if (s == 1) {
int last = qNorm.back();
qNorm.pop_back();
qNorm.push_front(last);
norm += (tot - last);
norm -= last * n;
norm += last;
last = qRev.front();
qRev.pop_front();
qRev.push_back(last);
rev -= (tot - last);
rev += last * n;
rev -= last;
}
else if (s == 2) {
swap(rev, norm);
swap(qNorm, qRev);
}
else if (s == 3) {
n++;
int k; cin >> k;
qNorm.push_back(k);
qRev.push_front(k);
norm += k * n;
rev += tot;
rev += k;
tot += k;
}
cout << norm << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
2094H - La Vaca Saturno Saturnita
Problem Credits: cry
What must the value of $$$a[i]$$$ be in order for $$$k$$$ to change?
$$$a[i]$$$ must be a divisor of $$$k$$$.
Can we use this to bound the number of times $$$k$$$ changes?
For each divisor $$$d$$$ of $$$k$$$, $$$k$$$ can only change once, because after the first iteration with $$$a[i] = d$$$, $$$k$$$ is no longer divisible by $$$d$$$. Thus, the number of times $$$k$$$ changes is bounded by the number of divisors of $$$k$$$.
Consider a particular query. We make the following two observations: first, the value of $$$k$$$ only changes if $$$a[i]$$$ is a divisor of $$$k$$$, and second, if there exists $$$a[i_1] = a[i_2]$$$ with $$$l\leq i_1 \lt i_2 \leq r$$$, then the value of $$$k$$$ will not change at $$$i=i_2$$$ (because after the iteration $$$i=i_1$$$, we have that $$$k$$$ is no longer divisible by $$$a[i_2]$$$).
This allows us to bound the number of times $$$k$$$ changes by $$$d(k)$$$, where $$$d(k)$$$ is the number of divisors of $$$k$$$. Note that the divisors of $$$d(k)$$$ can be found in $$$O(\sqrt{k})$$$ time by checking if $$$a$$$ divides $$$k$$$ for every $$$a$$$ from $$$2$$$ to $$$\sqrt{k}$$$, and if so, $$$a$$$ and $$$\frac{k}{a}$$$ are both divisors of $$$k$$$. Furthermore, at the scale constrained by the problem bounds, $$$d(k)$$$ is around $$$O(\sqrt[3]{k})$$$, so we only have to update $$$k$$$ at most $$$O(\sqrt[3]{k})$$$ times.
Now, we would like to find the first time each divisor of $$$k$$$ appears in $$$a[l], \dots, a[r]$$$. This can be done by storing the array $$$a$$$ in a map, where each value is mapped to a vector of indices where that values appears. Then for a given divisor of $$$k$$$, we can use lower_bound() (or generally, binary search) to find the smallest index at or after $$$l$$$ where this divisor appears, and we can check if it is no greater than $$$r$$$.
Now, we have a list of indices at which $$$k$$$ might change. So, suppose that $$$k$$$ changes to $$$k'$$$ at index $$$i_1$$$, and then changes to $$$k' '$$$ at index $$$i_2$$$ (and these are adjacent changes). Then we know that we have a value of $$$k'$$$ from $$$i=i_1$$$ to $$$i_2-1$$$, so we can add $$$k' \cdot (i_2 - i_1)$$$ to $$$ans$$$. We can then do this for all changes. This allows us to solve the problem in $$$O(n\log{n})$$$ preprocessing time and $$$O(\sqrt{k} + d(k)\log{n})$$$ time per query.
There are a few ways to optimize the runtime further, if your implementation is too slow. We can use a vector (of vectors) instead of a map, since $$$A = \max a_i = 10^5$$$ is reasonably small. Note that instantiating a vector of this size in every test case is too slow, so you may have to instantiate it globally and clear the vectors that were used after each test case.
Another optimization is to preprocess divisors instead of computing them on the spot. We can compute and store the divisors of all integers $$$2\leq a_i\leq 10^5$$$ in $$$O(A\log A)$$$ time in a vector of vectors where $$$divisor[a_i]$$$ contains all divisors of $$$a_i$$$ as follows: for all $$$2\leq i\leq A$$$, we push $$$i$$$ into $$$divisors[j]$$$ for all multiples $$$j$$$ of $$$i$$$. (The runtime follows from the fact that there are $$$\lfloor\frac{A}{i}\rfloor$$$ multiples of $$$i$$$ which are at most $$$A$$$, so across all $$$i$$$, we have at most $$$\frac{A}{1} + \frac{A}{2} + \cdots + \frac{A}{A} = A(\frac{1}{1} + \cdots + \frac{1}{A}) = AH(A) = O(A\log A)$$$ computations). This allows us to remove the $$$\sqrt{k}$$$ term in the runtime of each query.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
map<int, vector<int>> pos;
map<int, int> ptr;
int n, q; cin >> n >> q;
int arr[n+1];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
pos[arr[i]].push_back(i);
ptr[arr[i]] = 0;
}
vector<tuple<int, int, int, int>> qr(q);
int c = 0;
for (auto &[l, r, v, i]: qr) {
cin >> v >> l >> r;
i = c++;
}
vector<int> anss(q);
sort(qr.begin(), qr.end());
int prevL = 1;
for (auto [l, r, v, idd]: qr) {
for (int j = prevL; j < l; j++) {
ptr[arr[j]]++;
}
prevL = l;
vector<pair<int, int>> facts;
for (int i = 1; i * i <= v; i++) {
if (v % i == 0) {
int fact1 = v / i;
if (!(pos[fact1].size() == 0 || ptr[fact1] >= pos[fact1].size() || pos[fact1][ptr[fact1]] > r || fact1 == 1)) {
facts.push_back({pos[fact1][ptr[fact1]], fact1});
}
int fact2 = i;
if (fact2 == fact1) continue;
if (!(pos[fact2].size() == 0 || ptr[fact2] >= pos[fact2].size() || pos[fact2][ptr[fact2]] > r || fact2 == 1)) {
facts.push_back({pos[fact2][ptr[fact2]], fact2});
}
}
}
sort(facts.begin(), facts.end());
int pr = l;
int ans = 0;
for (auto [idx, val]: facts) {
int rr = idx - pr;
ans += v * rr;
while (v % val == 0) v /= val;
pr = idx;
}
if (facts.empty()) ans = v * (r - l + 1);
else ans += (r - pr + 1) * v;
anss[idd] = ans;
}
for (int i = 0; i < q; i++) cout << anss[i] << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}








I hope you all enjoyed the contest!
This is my first time writing an editorial — please let me know if there's anything unclear (or any mistakes). I'll read all of the replies to this comment and make any edits as necessary.
P.S. Thanks to temporary1 for proofreading, and for suggesting the optimizations on H.
temporary1 doing a serious thing? I don't believe you for a second.
you predicted F to be 900
yes, and I am a serious user.
The tutorial is very intuitive and easy to follow, as my solutions happen to match the tutorial ones on all the problems. I enjoy the whole set, particularly G and H as they offer challenges but not too hard for div 4. Thanks for the quick tutorial!
For hint 2 for problem G:
"It suffices to keep track of the current score, the score of the array if it were backwards, the size of the array, and the sum of the array."
No. You also need to know the last element.
In Hint 1, it says that we will be using a deque. In Hint 2, I ask what other values we have to maintain. These are the only other values we need to maintain; the last element is already being tracked by the deque.
What does "other" mean when you say "other values"? If you don't count the 'last element', why do you count 'the size'; isn't that also 'being tracked by the deque'?
You're right that in most languages, the standard library deque supports constant-time access of size, so it doesn't really have to be maintained. But technically a deque is just a data structure which supports pushing/popping and accessing on both ends — it doesn't by definition necessarily support size.
In any case, does a small wording difference like this really matter so much?
I don't view it as wording (otherwise I wouldn't be commenting about it). The size and sum of the array are very trivial to maintain. The problem, to me, was all about how to maintain the last element. Using two deques is clever and smarter than what I did.
You shouldn't need two deques, only one. (You can use two deques if you want, but the solution I presented only uses one.)
The idea of using a deque is in Hint 1, so I think semantically it's not necessary to include in Hint 2.
Loved the editorial, but(just interested) do the names of the problems have ANYTHING to do with the problem, or solution perhaps?
H is hard for me ;-;
Got filtered hard by F, but in hindsight it feels very simple...
One of the best Contest :)
For Italian
Lol, Indian?
This is a nice problem like H
At least the precomputation
liked the problems.. couldn't finish H in time, but the contest was well balanced! :)
bro ur plag is clear
if its plag report it to Cry
code for e also, please.
here was my solution for e, 315462682, i think e was pretty straightforward as long as you compared each bit independently.
Use [submission:315462682] instead. (Preview: 315462682)
DO NOT copy paste your raw code in comment.
In F I tried to fill the board in chess board manner, like filling all the black squares first and then all the white squares, what is the problem with this approach?
maybe number of elements are not same. share exacxt approach?
ofc ll is long long, didnt attach that piece of code, and lmao is the k given in question
you can see the test case bro
for 2 3 3 your code fails.
your output
1 2 1
3 2 3
2 and 2 are adjacent?
what if I handle this particular tc, will it work then? lemme try
I had a very similar implementation. I saw that it didn't work. In this case row is n and col is m: I said: if (n < m) { swap(n, m); switched = true; }
then at the end I dealt with printing the normal ones and the switched ones as two separate cases so I can get them back in format. It worked.. I don't know why this WOULD work, though. My submission (PASCALABC.NET): 320834015
i had the exact same idea but i found a test which fails. it was 2 rows and then something i dont really remember
i agree with SpyrosAliv, F was indeed 3500
who the hell predicted F 3500
Why is the time for query in H O(sqrt(k)+d(k)logn)? Shouldn't it be more since we have to go for every divisor not only for k, but for k',k'' and so on?
Every divisor or k',k'' and so on is also a divisor of k.
I have yet another optimization for H: 315473086. Instead of binary searching, you can store a queue of positions greater than or equal to the current. Then, you can access its first element in constant time. This requires you to process queries offline and in parallel: perform one jump for all queries starting at the current position before removing it from the queue.
Anyone who wants video solutions, can check out my screencast of this contest along with the solution explanations: https://www.youtube.com/watch?v=8WPZwkMQWng
(My solution to H is the same as the editorial but I didn't think it was neat enough, so I tried reallly hard to come up with another solution for that, but couldn't, and ultimately implemented the editorial solution)
ok bhaiya thanks
i've done pretty much the same as editorial but still got TLE https://mirror.codeforces.com/contest/2094/submission/315487879 can anyone help pointing out which part is probably taking too long?
multiplied by the number of test cases, this is TLE, need to make pos vector global.
shoot. you're right smh should've noticed that thanks for the help!
If possible can you tell whats wrong with my submission. https://mirror.codeforces.com/contest/2094/submission/322496621 Each query should be taking (FactorsCount) * (logN), which is the desired complexity in the editorial.
Did anyone notice the names of the problems? Very funny to be honest.
Actually, I wrote a whole storyline which went through all the problems. Unfortunately, it was deleted by the contest admin because it took up too much space in the statements and had no relation to the problems.
wow really I am interested can you type it here or it is not allowed ?
uhhh you'll have to ask cry
one doubt why the div 4 system testing takes too much time??
thanks
There's just a really really big number of submissions.
Just be patient.
yeah thanks got it
F is insane
just realization
315444303
macaquedev and SpyrosAliv claiming 900 and 3500 for F respectively is crazy lmao
It was a trivial problem for me. I saw the statement, and instantly saw the solution.... The only thing stopping me from writing 800 was the fact that the implementation is too long for 800.
you are a trivial person
It is very good round! But i think, G and H are easier that task F. I can`t solve constructivities(
Can someone explain to me, In problem F, why can not I fill the grid in chess board manner. I have tried so many testcases.315463534
Consider n=2, m=3 and k=3.
Output will be:
1 2 1
3 2 3
2 6 3
Ohh got it, Thankyou!
regardless of the parity of n and m, for this strategy to work we want nm/3 < (m(n-1)/2) + 1 because for k = 2 it always pass if nm/3 < rhs nm/4 also follows
nm/3 < m(n-1)/2 + 1
nm/3 <= m(n-1)/2
n/3 <= (n-1)/2
2n <= 3n — 3
n >= 3
solution only works for n >= 3. what is (m(n-1)/2) + 1 if your doubt, just start coloring some square from bottom go up and count the no of cells the first time they touch. like this
This is the first time I fail a problem because of declaring a vector locally instead of globally [H]. After getting the first TLE, I just assumed that what I was doing wasn't efficient enough and never thought to check for something as stupid as that... I guess for future reference, think more about what should be global and what shouldn't? But still, I can't believe I actually missed that.
Same here, I switched from map to vector of length 1e5 + 1 for each test case after my first TLE thinking it would be a harmless optimization, turns out it was the opposite.
Shalom
It's essentially the same thing as using
memsetfor the whole array, which thousands of people do every contest :)Damn it i found out F as constructive then quite it after 15 mins,then tried G and got my ass whooped throughout the contest by solving some equation.Turns out F was straightforward but NGL macaquedev must be tripping to rate it at 900.
Okay, I mean the entire tester server thinks I have a screw loose. Make what you will of that.
It was just a joke bro,I didn't really mean that
I know, my reply is also intended as humour.
As the Balon D'or winner, this contest was quite good, F was quite difficult however trivial once realised.
can someone explain why 315500513 is getting tle while 315500630 is not.
During a naive Python explanation, it does take more time to access a global variable than a local variable.
If you choose Python 3.13.2 as your language in SUBMIT tab, a tip saying " Almost always, if you send a solution on PyPy, it works much faster" will show. Therefore, DO NOT use Python 3.13.2 at any time, and use PyPy 3.10 (7.3.15, 64bit) instead.
Problem G uses the same trick as a problem I posted on Luogu in 2020: https://www.luogu.com.cn/problem/P6823
In problem D, I tried different approaches, but I got the wrong answer or TLE every time. Can anyone help me to solve this
My submission-(https://mirror.codeforces.com/contest/2094/submission/315460141)
my are u guys using dp isnt it simple iteration
If you prune the divisors after each iteration, and combined with offline processing, you can get $$$O(d)$$$ for each query.
Let $$$A[u]$$$ being the exponent of $$$u$$$ in the prime factorization of $$$A_i$$$, and $$$K[u]$$$ being the exponent of $$$u$$$ in the prime factorization of $$$K$$$.
The operation described in the problem is: Take $$$\min(\lfloor{\frac{K[u]}{A[u]}}\rfloor) \forall A[u] \gt 0$$$, let it be $$$x$$$. Then, for all prime $$$u$$$, $$$K[u]:=K[u]-x*A[u]$$$.
We consider the case when $$$x \gt 0$$$. Note that the number of divisors is $$$\prod{(K[u]+1)}$$$ [1].
Consider $$$u=argmin( \lfloor{\frac{K[u]}{A[u]}}\rfloor \forall A[u] \gt 0,\lfloor{\frac{K[u]}{A[u]}}\rfloor \gt 0 )$$$.
Clearly, the operation described above is $$$K[u]:=K[u]\mod A[u]$$$ for this $$$u$$$.
We have to prove that $$$\frac{K[u]\mod A[u]+1}{K[u]+1} \leq \frac{1}{2} \forall A[u]\leq K[u]$$$ [2].
This is equivalent to $$$K[u] \gt 2*(K[u]\mod A[u]) \forall A[u]\leq K[u]$$$.
Proof by contradiction: Assume $$$K[u]\leq 2*(K[u]\mod A[u])$$$.
Then, $$$K[u] \lt 2*A[u]$$$ since $$$K[u]\mod A[u] \lt A[u]$$$.
Since $$$A[u]\leq K[u] \lt 2*A[u]$$$, we have $$$K[u]\mod A[u] = K[u]-A[u]$$$.
Then, $$$K[u]\leq 2*(K[u]- A[u])$$$ or $$$K[u] - 2*A[u]\geq 0$$$, a contradiction.
From [1] and [2], we conclude that after each index that modifies $$$k$$$, the number of divisors of $$$k$$$ decrease at least by half. Using the geometric series, we conclude that the sum of number of divisors of $$$k$$$ after every iteration is bounded by $$$2*d$$$ (QED).
Proof_by_QED, add my submissions to the blog. I hope they are clear enough. Thank!
A: https://mirror.codeforces.com/contest/2094/submission/315387899
B: https://mirror.codeforces.com/contest/2094/submission/315422612
C: https://mirror.codeforces.com/contest/2094/submission/315433305
D: https://mirror.codeforces.com/contest/2094/submission/315445641
E: https://mirror.codeforces.com/contest/2094/submission/315466233
F: https://mirror.codeforces.com/contest/2094/submission/315414165
G: https://mirror.codeforces.com/contest/2094/submission/315403397
H: https://mirror.codeforces.com/contest/2094/submission/315380280
Sorry but in my opinion, model solutions should not include endless template code.
cry seems to love √N observations :) As a bit of context, first we got P2 on 2025 USACO US Open Gold[hardest problem in the contest], and we've also got H on this contest[also the hardest problem].
who wrote such a good second pretest at d bro?? like i spent 95 minutes on the problem and couldnt solve it
I tried to map the l and r from p to s, and was also stuck at test 2. I used the logic that say if I have an l in p, and one or two in s, then the l in p will be mapped to the l's in s. Then if there is an r next in p and s, the cycle will continue. But this will fail for the simple test case ,"LL LL" as the program counts the two l's in s as mapped from the first l in p, and gives an error as an l will be left in p. Did you use the same logic? 315469519
check my sol for D its quite easy using 2 pointers approach
I used following approach for 2094F - Trulimero Trulicina
We aim to construct an $$$n \times m$$$ grid using integers from $$$1$$$ to $$$k$$$, each appearing exactly $$$\frac{n \cdot m}{k}$$$ times, with no two adjacent cells having the same value.
When one of the dimensions is divisible by $$$k$$$:
Case A: $$$( n \bmod k = 0 ) $$$
a[i][j] = ((i + j) % k) + 1Case B: $$$( m \bmod k = 0 )$$$
a[i][j] = ((j + i) % k) + 1These cyclic patterns rotate values so that no adjacent cells share the same value.
When neither $$$n$$$ nor $$$m$$$ is divisible by $$$k$$$:
Factor $$$k$$$ into two integers $$$nn$$$ and $$$mm$$$ such that:
Steps:
a[i][j] = tile[i % nn][j % mm]This guarantees: Equal frequency and no two adjacent cells share the same value.
Summary
Check 315555434 for implementation if you wish to :D
We can avoid using an additional
dequeby simply maintaining a boolean flag to track whether the current state is reversed or not in 2094G - Chimpanzini Bananini.Check the submission for reference : 315552863
Shouldn't there be multiple solutions of B?
315354810
I have a solution for 2094H - La Vaca Saturno Saturnita with a better bound.
Precompute divisors of all numbers in $$$\mathcal{O}(A \log A)$$$.
Each query will be processed in this way:
Process all queries in parallel, so that information about closest element with given value is available in $$$\mathcal{O}(1)$$$ for all values at any point.
This operation
has $$$2$$$ limitations:
(1) It reduces the value of $$$k$$$ by at least twice on each iteration. It applies the limit on total number of loop iterations as $$$\mathcal{O}(\log k)$$$. This is also the limit on number of jumps.
(2) It reduces the number of divisors of $$$k$$$ or by at least twice after all iterations on a single element $$$a[i]$$$. Consider factorizations of $$$k$$$ and $$$a[i]$$$
$$$F(k, p) = (1 + F(k/p, p)) \;\textrm{if}\; k \bmod p = 0 \;\textrm{else}\; 0$$$
$$$k = \prod\limits_{p \in \mathbb{P}} \textrm{pow}(p, F(k, p))$$$
$$$d(k) = \prod\limits_{p \in \mathbb{P}} 1 + F(k, p)$$$
For any $$$k$$$ and $$$a[i]$$$ that $$$k \bmod a[i] = 0$$$ there exists such prime $$$p$$$ that
$$$F(k', p) = F(k, p) \% F(a[i], p)$$$
then
$$$2 \cdot F(k', p) \lt F(k, p)$$$
$$$2 \cdot (F(k', p) + 1) \leqslant F(k, p) + 1$$$
$$$2 \cdot d(k') \leqslant d(k)$$$
Thus instead of $$$\log k$$$ jumps $$$\mathcal{O}(d(k))$$$ each, we actually have $$$d(k) + d(k') + d(k' ') + \ldots = d(k) + d(k)/2 + d(k)/4 + \ldots = \sum\limits_{i=0}^{log_2 k} \frac{d(k)}{2^i} \lt 2 \cdot d(k)$$$
Compexity per query is then $$$\mathcal{O}(\log k + d(k))$$$. Total complexity is then $$$\mathcal{O}(A \log A + q \log k + q \cdot d(k))$$$
315489102
I am not clear with solution and approach of problem H not understanding very easily can u make simple reirugan
Sure, I'm happy to make changes.
Can you be more clear on what exactly you're not understanding?
which algorithm we are doing with, not having clarity reirugan
There is no specific algorithm that you need to know to solve this problem. The only knowledge that is necessary is that which is presented in the solution.
Is there something specific in the solution that is unclear?
If u don't mind can u give some tips to increase my cp rating please reirugan
Read the blogs in the General Advice section of the Catalog: https://mirror.codeforces.com/catalog
where is Tralalero Tralala?
Where are ballerina capuchina and bombordiro crocodilo problems. They are the GOAT.
Easy problems, should've put bombardiro crocodilo instead
For 2094C — Brr Brrr Patapim ----- More optimised Code than the editorial one
Using the logic of missing number to find the p1
H is a very good question, and I didn't think of the approach at all.
Is l in Problem B always less than or equal to diff? If so, what's the point of this condition?
what the fuck are these names br0.