Thanks for participating in the round. We hope you enjoyed the problems!!!
2278A - Fraction and Six
The problem requires the remaining characters in the numerator $$$p$$$ to form exactly the string six after completely cancelling out the denominator $$$q$$$.
This means the collection of characters in $$$p$$$ must be exactly the characters in $$$q$$$ combined with the letters s, i, and x. Therefore, if we append the string six to $$$q$$$, the modified string $$$q$$$ must be an exact anagram of $$$p$$$. We can check this condition by sorting both strings and verifying if they are identical, or by comparing their character frequency counts.
Time Complexity: $$$\mathcal{O}(n + m)$$$.
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n, m;
string p, q;
cin >> n >> m >> p >> q;
q += "six";
vector<int> pc(255, 0), qc(255, 0);
for(auto& z : p) pc[z]++;
for(auto& z : q) qc[z]++;
if(pc == qc) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
2278B - Stakes and Shapes
Let's consider a strategy where Bob plays the exact same move in all $$$x+y+z$$$ rounds.
If Bob chooses to always play the move that beats Alice's most frequent choice, the number of rounds he wins will be exactly the maximum of $$$x, y,$$$ and $$$z$$$.
Alice will only win the rounds where she plays the move that beats Bob's choice. The number of rounds she wins will correspond to one of the other two frequencies.
Since the maximum frequency is at least as large as the remaining frequencies, the number of rounds Bob wins will always be at least the number of rounds Alice wins. Therefore, the optimal sequence is to simply find the maximum of $$$x, y,$$$ and $$$z$$$ and output its counter-move $$$x+y+z$$$ times.
Time Complexity: $$$\mathcal{O}(x+y+z)$$$.
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
vector<int> a(3);
cin >> a[0] >> a[1] >> a[2];
string s = "PRS";
int total = a[0] + a[1] + a[2];
for(int i = 0; i < total; i++){
cout << s[max_element(a.begin(), a.end()) - a.begin()];
}
cout << '\n';
}
return 0;
}
2278C - Math and Physics
Let's analyze how the total mass of the array changes during an operation.
When we choose to operate on an inner core ($$$1 \lt i \lt k$$$), its mass $$$a_i$$$ is partitioned into two parts $$$x$$$ and $$$y$$$ ($$$x, y \ge 1$$$), which are completely absorbed by the left and right neighbors. Thus, the total mass of the array is perfectly conserved.
However, if we operate on an edge core ($$$i = 1$$$ or $$$i = k$$$), one of the split parts falls out of bounds. This means we permanently lose at least $$$1$$$ unit of mass to the environment.
To reduce the array to a single core, we must eventually reach a state with exactly $$$2$$$ cores. To merge them, we are forced to operate on one of them. Since both are edge cores at that point, it is strictly impossible to avoid losing at least $$$1$$$ unit of mass. Therefore, the theoretical maximum final mass is bounded by $$$\sum_{i=1}^n a_i - 1$$$.
Now, can we always achieve this upper bound? Let's classify the initial state into three cases:
Case 1: All initial elements are $$$1$$$. The operation strictly requires an element to be $$$\ge 2$$$. No moves can be made, so it is impossible to reduce the array. In this case, we print $$$-1$$$.
Case 2: There exists at least one inner element $$$a_i \ge 2$$$ ($$$1 \lt i \lt n$$$). We can choose this inner core for our first operation. Because $$$x \ge 1$$$ and $$$y \ge 1$$$, we pass at least $$$1$$$ unit of mass to both its left and right neighbors. Since every core initially has a mass of at least $$$1$$$, these neighbors will now have a mass of at least $$$2$$$.
This means we can continue expanding outwards, exclusively operating on inner cores. We can reduce the entire array down to $$$2$$$ elements without ever losing mass to the environment. The only mass lost is the unavoidable $$$1$$$ unit at the very end. The answer is exactly $$$\sum_{i=1}^n a_i - 1$$$.
Case 3: All inner elements are $$$1$$$, but an edge element is $$$\ge 2$$$ (or $$$n = 2$$$). Because there are no valid inner cores to start with, we are forced to operate on an edge core. To minimize our losses, we split it into $$$1$$$ (which is lost to the void) and $$$a_i - 1$$$ (which is added to the adjacent inner $$$1$$$). That inner core now has a mass of $$$a_i \ge 2$$$ and effectively becomes the new edge of the remaining array. To clear out all $$$n-2$$$ inner $$$1$$$s, we must repeat this "rolling" process, paying a toll of exactly $$$1$$$ unit of mass for every inner element we consume. In total, we lose $$$n-2$$$ mass to clear the inner elements, plus the $$$1$$$ mass lost during the final merge. The total mass lost is $$$n-1$$$. The final mass is $$$\sum_{i=1}^n a_i - (n - 1) = a_1 + a_n - 1$$$.
Time Complexity: $$$\mathcal{O}(n)$$$.
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> a(n);
for(auto& z : a) cin >> z;
int sum = accumulate(a.begin(), a.end(), 0);
if(sum == n) cout << -1 << '\n';
else if(sum == n - 2 + a[0] + a[n - 1]) cout << a[0] + a[n - 1] - 1 << '\n';
else cout << sum - 1 << '\n';
}
return 0;
}
2278D - Lock and Unlock
Let $$$b_1 \le b_2 \le \dots \le b_n$$$ be the sorted version of the initial array $$$a$$$. To make all elements equal, our goal is to reduce the gap $$$b_{i+1} - b_i$$$ to zero for all $$$1 \le i \lt n$$$.
To close the gap between $$$b_i$$$ and $$$b_{i+1}$$$ by $$$1$$$ unit, they must move closer relative to each other. Suppose we decide to increase $$$b_i$$$. If we do not also increase all elements to its left ($$$b_1 \dots b_{i-1}$$$), we will successfully close the gap on the right, but we will simultaneously widen the gaps within the left group. Therefore, to guarantee we never undo our progress or create new gaps, any time we shift elements to close a specific gap $$$b_{i+1} - b_i$$$, we must shift the entire group of elements on one side of that gap as a single rigid block.
Now, to reduce $$$b_{i+1} - b_i$$$ by $$$1$$$ unit, we only have two optimal choices:
- Lock the prefix $$$b_1 \dots b_i$$$ (incurring a cost of $$$i$$$) and decrease the entire suffix $$$b_{i+1} \dots b_n$$$.
- Lock the suffix $$$b_{i+1} \dots b_n$$$ (incurring a cost of $$$n-i$$$) and increase the entire prefix $$$b_1 \dots b_i$$$.
Since these choices are independent for every gap, we can greedily take the cheaper option. The minimum cost to close the gap $$$b_{i+1} - b_i$$$ by $$$1$$$ unit is exactly $$$\min(i, n-i)$$$. Summing this over all gaps in the array, the minimum possible total cost is exactly:
To find the minimum number of operations needed, note that in any single operation, an element's value changes by $$$+1, -1$$$, or $$$0$$$. Therefore, the absolute maximum distance in the array, which is initially $$$b_n - b_1$$$, can decrease by at most $$$1$$$ in a single operation. To make all elements equal, this distance must be reduced to $$$0$$$. Thus, we strictly need at least $$$b_n - b_1$$$ operations.
Observe that in any operation, we are either increasing some prefix by $$$1$$$ or decreasing some suffix by $$$1$$$. In any case, the value of $$$b_n - b_1$$$ decreases by $$$1$$$. This guarantees that the maximum span shrinks in every operation, achieving the minimum cost in exactly $$$b_n - b_1$$$ operations.
Time Complexity: $$$\mathcal{O}(n \log n)$$$.
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> a(n);
for(auto& z : a) cin >> z;
sort(a.begin(), a.end());
long long cost = 0;
for(int i = 0; i < n - 1; i++){
cost += 1ll * (a[i + 1] - a[i]) * min(i + 1, n - i - 1);
}
cout << cost << ' ' << a[n - 1] - a[0] << '\n';
}
return 0;
}
2278E - Swap and Negate
Let's define a new array $$$b$$$ such that $$$b_i = (-1)^{i-1} a_i$$$.
Now, let's take a look at how the given operation affects this new array $$$b$$$. If we apply the operation at index $$$i$$$, the new values in $$$a$$$ become $$$a'_i = -a_{i+1}$$$ and $$$a'_{i+1} = -a_i$$$. Observe the corresponding elements in $$$b$$$:
Surprisingly, the operation on $$$a$$$ translates to exactly swapping adjacent elements in $$$b$$$!
Since we can swap adjacent elements any number of times, we can rearrange $$$b$$$ into any permutation we want. This is the core idea of the problem. All that's left is just some math. Now, let's express the sum of the array $$$a$$$ in terms of $$$b$$$:
To maximize this total sum, we greedily place the smallest $$$\lfloor \frac{n}{2} \rfloor$$$ elements of the array $$$b$$$ at even indices and the largest $$$\lceil \frac{n}{2} \rceil$$$ elements at odd indices. The resulting alternating sum of the array $$$b$$$ is the required answer.
Time Complexity: $$$\mathcal{O}(n \log n)$$$.
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> a(n);
for(auto& z : a) cin >> z;
vector<int> b = a;
for(int i = 1; i < n; i += 2) b[i] = -b[i];
sort(b.begin(), b.end());
int i = 0;
long long ans = 0;
for(; i < n / 2; i++) ans -= b[i];
for(; i < n; i++) ans += b[i];
cout << ans << '\n';
}
return 0;
}
2278F - Modulo and Counting
For any two positive integers $$$x \ge y$$$, we can write $$$x \bmod y = x - k \cdot y$$$, where $$$k = \lfloor \frac{x}{y} \rfloor \ge 1$$$.
Let $$$k_i = \lfloor \frac{a_i}{a_{i+1}} \rfloor$$$. Since the array is non-increasing ($$$a_i \ge a_{i+1}$$$), we are guaranteed that $$$k_i \ge 1$$$. We can rewrite the modulo sum condition as:
Upon rearranging, we get:
Let's bound the right-hand side. We are given $$$a_1 \le m+2$$$ and $$$a_n \ge 1$$$. Thus, the maximum possible value for $$$a_1 - a_n - m$$$ is $$$(m+2) - 1 - m = 1$$$. Because $$$k_i \ge 1$$$ and $$$a_{i+1} \ge 1$$$, every term in the summation on the left is non-negative. This strictly bounds the sum to be either exactly $$$0$$$ or exactly $$$1$$$. Observe that this also imposes the additional constraints $$$a_n \le 2$$$ and $$$a_1 \ge m + 1$$$.
Now, if $$$a_n = 2$$$, we must have $$$a_1 = m + 2$$$. Note that this forces every $$$k_i$$$ to be exactly equal to $$$1$$$. So, we must have $$$a_{i+1} \le a_i \lt 2a_{i+1}$$$.
If $$$a_n = 1$$$, consider the exact step where the sequence drops to $$$1$$$ from some value $$$x \ge 2$$$. For this specific step, $$$a_j = x$$$ and $$$a_{j+1} = 1$$$. The quotient is $$$k_j = \lfloor \frac{x}{1} \rfloor = x$$$. See that if $$$x \ge 3$$$, the left-hand side is at least $$$2$$$, and this is not allowed. This forces the constraint $$$x \le 2$$$. Thus, we must have $$$x = 2$$$. This proves that if the sequence drops to $$$1$$$, it must drop exactly from the value $$$2$$$. This makes the left-hand side at least $$$1$$$, and consequently, the right-hand side of our equation must be exactly $$$1$$$, implying $$$a_1 = m + 2$$$. Similar to the previous case, every $$$k_i$$$ ($$$i \lt j$$$) is forced to be exactly equal to $$$1$$$. So, we must have $$$a_{i+1} \le a_i \lt 2a_{i+1}$$$.
Generalizing things, an array $$$a$$$ is good if and only if it satisfies all of the following conditions:
- $$$a_1 = m + 2$$$;
- $$$a_j = 2$$$ for some index $$$j \in [2, n]$$$;
- $$$a_k = 1$$$ for all $$$j + 1 \le k \le n$$$;
- $$$a_{i+1} \le a_i \lt 2a_{i+1}$$$ for all $$$1 \le i \lt j$$$.
To count the number of good arrays, we use 2D DP. Let $$$\text{dp}[i][v]$$$ ($$$1 \le i \le n$$$; $$$2 \le v \le m + 2$$$) denote the number of valid prefixes of length $$$i$$$ with an additional constraint $$$a_i = v$$$. The base case would be $$$\text{dp}[1][m+2] = 1$$$ and $$$\text{dp}[1][x] = 0$$$ for all $$$x \neq m + 2$$$. The transition is straightforward:
Any valid sequence that safely hits $$$2$$$ at length $$$i$$$ will just be padded with $$$1$$$s for the remaining $$$n-i$$$ elements. This padding is unique and deterministic. Therefore, to find the total number of good arrays of length $$$n$$$, we simply sum the number of ways to reach the value $$$2$$$ at any valid length $$$i$$$:
This DP has $$$\mathcal{O}(nm)$$$ states, and each transition requires a contiguous range sum of the previous row. By maintaining a prefix sum of the DP table, we can compute each state in constant time, yielding an optimal solution in $$$\mathcal{O}(nm)$$$ time and space. It is useful to note that one can also optimize the space complexity to $$$\mathcal{O}(m)$$$ (refer to the implementation below).
Time Complexity: $$$\mathcal{O}(nm)$$$.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 998'244'353;
int main(){
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
vector<ll> dp(m + 3, 0);
dp[m + 2] = 1;
ll ans = 0;
for(int i = 1; i < n; i++){
ll sum = (dp[2] + dp[3]) % mod;
int left = 2, right = 3;
for(int j = 2; j < m + 3; j++){
ll temp = sum;
sum += (mod - dp[left]);
left++;
right++;
if(right < m + 3) sum += dp[right];
right++;
if(right < m + 3) sum += dp[right];
sum %= mod;
dp[j] = temp;
}
ans += dp[2];
ans %= mod;
}
cout << ans << '\n';
}
return 0;
}
2278G - 0s and 1s
Observe the behavior of an injected energy pulse. If a node is at state $$$0$$$, it becomes $$$1$$$ and stops. If it is $$$1$$$, it becomes $$$0$$$ and sends a pulse to its children. Notice that this is exactly the mechanism of binary addition. Flipping from $$$0 \to 1$$$ is adding $$$1$$$ without a carry. Flipping from $$$1 \to 0$$$ and passing a pulse is adding $$$1$$$ and generating a carry to the next significant bit.
Consider a path from the root down to a node $$$v$$$ at depth $$$d$$$ (0-indexed). The initial states of the nodes on this path form a binary integer $$$X_v$$$, where the root represents the least significant bit (LSB) and $$$v$$$ represents the $$$d$$$-th bit. Because the carry rules are identical, injecting $$$K$$$ pulses at the root is mathematically equivalent to computing the sum $$$X_v + K$$$ for every path simultaneously.
The final state of node $$$v$$$ after $$$K$$$ pulses will simply be the $$$d$$$-th bit of the sum $$$X_v + K$$$. We require this final state to be exactly $$$y_v$$$.
Since $$$K$$$ is a single global integer, we can determine it bit by bit, level by level. Let $$$k_d$$$ be the $$$d$$$-th bit of $$$K$$$. Let $$$C_v$$$ be the incoming carry bit that node $$$v$$$ receives from its parent. For the root, $$$C_{\text{root}} = 0$$$.
For any node $$$v$$$ at depth $$$d$$$, the $$$d$$$-th bit of the sum $$$X_v + K$$$ is calculated as:
We need this to equal $$$y_v$$$. Rearranging the equation gives us the required $$$d$$$-th bit of $$$K$$$:
This creates a strict constraint: for a valid $$$K$$$ to exist, the required $$$k_d$$$ must evaluate to the exact same value for all nodes at depth $$$d$$$. If any two nodes at the same depth yield a different $$$k_d$$$, it is impossible to satisfy both simultaneously. We print $$$-1$$$ in this case.
If all nodes at depth $$$d$$$ agree on $$$k_d$$$, we lock in this bit for $$$K$$$. We then compute the outgoing carry that node $$$v$$$ will pass to its children for the next depth:
The final answer is computed by summing $$$2^d$$$ for all depths $$$d$$$ where $$$k_d = 1$$$. Since we process each node exactly once and only do constant-time bitwise operations, the complexity is linear.
Time Complexity: $$$\mathcal{O}(n)$$$.
#include<bits/stdc++.h>
using namespace std;
const int mod = 998'244'353;
const int MX = 200005;
vector<int> p2(MX, 1);
void init(){
for(int i = 1; i < MX; i++) p2[i] = 2 * p2[i - 1] % mod;
}
int main(){
init();
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<vector<int>> v(n + 1);
for(int i = 1; i < n; i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
string x, y;
cin >> x >> y;
x = "." + x;
y = "." + y;
vector<int> dep(n + 1, 0), par(n + 1, 0);
function<void(int, int)> dfs = [&](int u, int p){
for(auto& z : v[u]) if(z != p){
par[z] = u;
dep[z] = 1 + dep[u];
dfs(z, u);
}
};
dfs(1, -1);
vector<int> carry(n + 1, 0);
vector<vector<int>> nodes(n);
for(int i = 1; i <= n; i++) nodes[dep[i]].push_back(i);
int ans = 0;
bool is = 1;
for(int i = 0; i < n && is; i++){
bool req[2] = {0, 0};
for(auto& z : nodes[i]){
int xb = x[z] - '0';
int yb = y[z] - '0';
int cb = carry[par[z]];
int rb = xb ^ yb ^ cb;
req[rb] = 1;
if(xb + cb + rb > 1) carry[z] = 1;
}
if(req[0] && req[1]) is = 0;
ans += req[1] * p2[i];
ans %= mod;
}
if(!is) ans = -1;
cout << ans << '\n';
}
return 0;
}








G can also be solved using hashing
F absolutely cooked me ion even deserve 1600
bit on the easier side but W round!
the person who wrote the statement of problem A deserves 1000+ downvote..
Don't you solve those questions like that irl too
*public execution.
it was good ig, the one who deserves execution is the author who used "rock scissor paper" instead of "rock paper scissors"
true dude
As noob, I hate C.
In every prob, 67 in the example saved me from depression
Fasteditorialforces
pov: 6 7 in every possible sample
Fuck E bro it's should've been replaced with H
Why is the checker for B Case sensitive :'(
Why B simple solution why
B is solved simply because if we take x+y+z times opposite to the most frequent enemy peak, then the enemy will lose at least max(x, y, z) times. After that, he will win x or y or z times, and then there will be a draw x or y or z times. And the opponent is in no way able to achieve a positive score, because we will win max(x,y,z) times, and he is only x or y or z
I know, it's just both funny and annoying how much I overthought it.
2278A - Fraction and Six I'm new to completive programming, and coding in general. It always fascinates me how my extremely long solution could be done so short.
What was wrong with this contest?! A-E was pure greedy and F jumped to a hell (it was really hard) dp
Whoever kept Rock,Scissor,Paper in Problem B (instead of Rock,Paper,Scissor) .. is pure evil
Thats true brother. had me the first time. i would have gotten it at first if i just used = signs in the conditions.
Did anyone use maps in A?
i did..
i used mutiset...
A, B, C, D and even E being greedy feels so weird
Problem D: Why is the editorial so complicated? This is just the classic "min operations to make all elements equal" problem in disguise.
Locking a group and moving the rest is the same as moving that group by +-1 relative to the others, so the cost is just the number of single-element +-1 moves. That's the sum of |a[i] — median|, so sort and take the median. The number of operations is just max — min, since each operation shrinks it by at most 1.
(The editorial's sum over gaps of (b[i+1] — b[i]) * min(i, n-i) is the same number, it's just counting the cost gap by gap.)
Code:
dang, why the downvotes — this is exactly how i thought about it
+1. This is how I solve this problem, too.
why tf do u have downvotes!, thats how d should be done
Affirmative. I also solved it this way. By the way you can find the median with C++'s nth_element() instead of sorting to achieve a time complexity of O(n).
You're Wrong!You ignore the complexcity of the function!It's not better than O(n)!
What do you mean when you said I ignored the complexity of the function? I am pretty sure that the time complexity of nth_element() is O(n).
Also, I did not say it was better than O(n), but that nth_element() in O(n) was better than sort() in O(n log n).
I beg your pardon — I was wrong. I misunderstood the complexity of nth_element() and my earlier reasoning was off. You were right to call it out. Sorry about that and thank you for your patience.
I had same idea and its straight forward to implement.
I thought this way too.This is a beautiful method to solve the problem and your proof is simple and clear.Pretty good!
i didnt get the intution of median. i solved greedily from prefix or suffix
Yes, this idea is more easy to understand. I just do it like this.
Anyone who has solved E, how do you come up with the solution given in editorial, or any solution to E for that matter ?! Thank you.
We can argue that the sign that an element can take after any sequence of operations is tied to its initial sign and index parity. For example, an element with value -5 initially at an even index can only have -5 value at any other even index, and +5 at any odd index. The signs for an element are hence alternating (+-+-.. or -+-+...)
With this we can divide elements into two groups — the elemnts whose sign-map starts with — and those whose sign map starts with +.
elements in the same group compete for +ve positions, and we assign those positions to the largest elements in that group to maximize the score. There are a few more caveats to the implementation, but this is the basic idea.
yes, and for me, it was the sample
-10 1 0 1 -10which gave away the parody index idea, I was like hmm the answer involves making both 10's positive and both 1's negative, so we can't make everything positive -> what is it about the 10's and 1's -> oh, the 10's are on even indexes, the 1's are on odd indexesThe first observation was: if you move an element an odd number of times, the number is multiplied by -1. If you move it an even number of times, the number remains the same.
This leads to an observation: a number is multiplied by -1 if and only if initially it was at an odd index and it has moved to an even index, or initially it was at an even index and it has moved to an odd index.
Now, if we move x elements from odd to even, then we have to also move x elements from even to odd, because for every element you move to the other group, you have to bring one element back from that group.
Now the problem becomes a bit easier. Create an array of all odd indices and an array of all even indices. Brute force on the number of elements you want to multiply by -1, and change the signs of the smallest elements in each group.
396819444
Your solution is very intuitive unlike the invariant solution that people are using like saying (-1)^i * ai is constant always.
Why don't authors write solutions like this ?! I mean, they put in so much effort and have the patience to withstand long waits in the queue. And I'm sure they're capable of writing solutions like this. Right ?!
very nice explanation , much appretiated
I think you could've made G a bit harder by allowing to perform the operation on subtrees as well. Similar solution should also work for the harder version.
Can someone please explain what is wrong here ? I am trying to calculate min cost by making all the elements of array equal to arr[i]
Your idea was to calculate the distance of all numbers from the minimum to the maximum. You asked about an error in the code – take a look at where you’re calculating the distance and operations from all the numbers to the minimum; you’re multiplying by i + 1. Presumably, your logic was that you would cover the elements in this prefix, but the trick is that you can cover the suffix up to i + 1 and get a lower score; I wrote the exact same algorithm at first, but then came to the same realisation.
btw your idea with diff arr is right
F is really interesting. It's definitely a bit on the harder side compared to other div 3s imo.
It looks hard until you realise that the crux of the problem was: with this condition on a, the maximum sum you can get is m.
Now figure out the necessary conditions for the sum to be m and write a DP on it.
After taking the upper bound on An and then proving 1 can only be succeeded by 2 felt a bit non intuitive maybe because I have never seen a similar idea. After that the problem was trivial. Thank you.
greedyforces
Crazy difficulty jump from E to F but I ended up on the good side of that difficult jump (solving first 5 within an hour) so I'll take it.
In my opinion, F is harder than G
The pretests for A is so weak.
I feel bad for all the people that are gonna lose their credit for problem A due to WA when final verification happens.
How can someone know to start with forming the array-b in problem E? Is there any clue?
As an overthinker, I hate greedy...
my 2nd contest and the problems were good ngl I could only solve the a b c but it is what it is
The problem C, I couldn't understand the condition they gave, is it only confusing for me or for you all
There are n nuclear cores arranged in a line, numbered from 1 to n from left to right. The i-th core has an initial mass of ai.
In one operation, you can choose a core i(1≤i≤k, where k is the current number of cores)
What I thought is that i is fixed from the start and k will be current size
like for example if they gave masses -> 1 1 1 5 1 1 1 1 the positions are 1(1) 1(2) 1(3) 5(4) 1(5) 1(6) 1(7) 1(8)
So what I thought is I can only split if (4 <= current size(8), obv every position is >= 1)
then after splitting, I thought the positions would not change but in editorial they just did it so naively, I donno if I couldn't understand and overthought or they couldn't frame question properly
1(1) 1(2) 2(3) 6(5) 1(6) 1(7) 1(8)
now I thought I can only split position 5 one since it's <= current size(7)
1(1) 1(2) 3(3) 7(6) 1(7) 1(8)
and goes on I thought I can only split if it's less than current size
and I wrote a condition that if there are more than 3 last ones then it's -1 impossible to convert into 1 single
Anyone had same thoughts ?
The Problem E is good but the editorial is little overwhelming . Here is my idea for it.
If we look at the array a with 3 indices suppose [u,v,w] and try to perform some operations on it. we will see that it can be changed to [w,v,u] and so it concludes that elements order at even and odd indices can be changed to any permutation . If we sort the elements at odd indices and even indices separately and reassign the new array a according to indices, we can see now a more clear picture. This new order of elements will show us that the negative integers are more aligned on left side and positive elements on right side in new array. Till this point we have only changed the permutation but the sum is still the same as the original array.
Now On new array a we have a choice to either perform operation or not. for this we can use DP to do a choice . --> dp[i-2]-a[i]-a[i-1] // operation performed --> dp[i-1] + a[i] // no operation performed will assign max of above 2 in dp[i] .
I believe this dp part code can be done using greedy solution. but DP does not betray.
Same solution, but I used greedy. After sorting I check every pair $$$a[2k-1]$$$ and $$$a[2k]$$$ and add the absolute value of their sum.
Attention is all me need, but I don't have extremely attention. How To attend the important condition in problem E?
Coming back to CP after a while, some similar problems like F would help ramp up faster. Can someone point me in the right direction?
A was accepted in the contest time but now it is showing Wrong Answer .
What the f.....
I experienced the same thing, maybe they have rerun those tests for problem you've solved and now it's WA. Or maybe you just imagined it?
At contest time, there were bad test cases, after contest there is hacking phase right, if people think the test cases are not good enough they'll add better test cases, so if they can find hack(a testcase) which suppose doesn't work with your code they'll add that test case and re run everyone's code kind of
Oh ok I think you just opened my mind
Bro I was writing code for problem 'A' for 1 HOUR :sob:, which means — more practice!
Difficulty jump from E to F was insane
I felt that G was easier than F
The idea I had for E was a bit different (and I think similar to what others have done), but the editorial solution is quite pretty, I have to admit
I really liked the 2278E - Swap and Negate. The transformation idea $$$b_i=(−1)^{i−1}a_i$$$ is simply generous! I wish to practice more of this kind. Could anyone find me some similar problems?
first contest let me fumble got cooked by A
D can be done with Ternary Search. It's like killing an ant with a bomb, but who would say killing an ant with a bomb isn't fun?
apparently the HXH narrator didn't like it
Good idea! Why didn't I expect to write like this.
You can think of problem F as having a score and potential energy. Define the potential to be the last element in the added in our array.
Ex: [10], potential = 10, score = 0 The key idea is that adding the next element, adds the remainder to the score, and the new potential becomes the last element. For example, lets add 7 to the end of our array.
[10, 7], potential = 7, score = 3
Lets add a 4:
[10, 7, 4], potential = 4, score = 6
The observation is that as long as we keep adding elements greater than half the last element. The sum of our score & potential do not change. Which means that if we can keep adding elements greater than last / 2, the potential will be conserved, so we end with a score of the first element.
Two details: 1) Since we cannot add an element less than 1, this means our score will lose 1 unit of potential. 2) It is not possible to add a 1 unless you break the rule of the element being > last / 2. Which means you will lose another 1 unit of potential by either adding a 1, or keeping the last element to be a 2.
This means that if we start at a number x, our score can be atmost x — 2. This implies that the only valid starting is m + 2. And that we must follow the above rules to guarantee that we only lose the 2 points of potential
problem E...how am i even supposed to start thinking in the direction of making a new array
I was stuck just trying to find if i can somehow do something with even and odd positions the whole time.
Please give any advice.