I hope everyone enjoyed the tasks, and thank you for participating.
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> x(n);
for (int i = 0; i < n; ++i) {
cin >> x[i];
}
sort(x.begin(), x.end());
if (x[0] % 2 == x[n - 1] % 2) {
cout << 0 << endl;
return;
}
int left = n, right = n;
for (int i = 1; i < n; ++i) {
if (x[i] % 2 != x[0] % 2) {
left = i;
break;
}
}
for (int i = 1; i < n; ++i) {
if (x[n - i - 1] % 2 != x[n - 1] % 2) {
right = i;
break;
}
}
cout << min(left, right) << '\n';
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
Editorial
Tutorial is loading...
Solution
#include "bits/stdc++.h"
#define int long long
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define em emplace_back
#define mp make_pair
#define F first
#define S second
using namespace std;
template<class C>
using vec = vector<C>;
using vi = vector<int>;
using vpi = vector<pair<int, int>>;
using pii = pair<int, int>;
void solve() {
string s;
cin >> s;
int n = s.size();
int bal = 0;
for (int i = 1; i + 1 < n; i++) {
if (s[i] == '(') bal++;
else bal--;
if (bal < 0) {
cout << "YES\n";
return;
}
}
if (bal == 0) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
signed main() {
int tt;
cin >> tt;
while (tt--) {
solve();
}
}
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> d(n);
for (auto &x : d) {
cin >> x;
}
vector<int> l(n), r(n);
for (int i = 0; i < n; ++i) {
cin >> l[i] >> r[i];
}
int left = 0;
vector<int> last;
for (int i = 0; i < n; ++i) {
if (d[i] == -1) {
last.push_back(i);
} else {
left += d[i];
}
while (left < l[i]) {
if (last.empty()) {
cout << -1 << '\n';
return;
}
d[last.back()] = 1;
++left;
last.pop_back();
}
while (left + last.size() > r[i]) {
if (last.empty()) {
cout << -1 << '\n';
return;
}
d[last.back()] = 0;
last.pop_back();
}
}
for (auto &x : d) {
cout << max(0, x) << " ";
}
cout << "\n";
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 11;
struct edge {
int t, w;
edge(int t, int w) : t(t), w(w) {}
};
void solve() {
int n, m;
cin >> n >> m;
vector<int> b(n);
for (auto &x : b) {
cin >> x;
}
vector<vector<edge>> graph(n);
for (int i = 0; i < m; ++i) {
int s, t, w;
cin >> s >> t >> w;
--s; --t;
graph[s].push_back(edge(t, w));
}
auto check = [&](int maxW) {
vector<int> best(n, 0);
for (int i = 0; i < n; ++i) {
if (i > 0 && best[i] == 0) {
continue;
}
best[i] += b[i];
best[i] = min(best[i], maxW);
for (auto p : graph[i]) {
if (p.w <= best[i]) {
best[p.t] = max(best[p.t], best[i]);
}
}
}
return (best.back() > 0);
};
if (!check(INF)) {
cout << -1 << endl;
return;
}
int l = 0, r = INF;
while (r - l > 1) {
int mid = (l + r) / 2;
if (check(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
vector<set<int>> graph;
vector<int> ans;
void dfs(int v) {
while (!graph[v].empty()) {
int u = *graph[v].begin();
graph[u].erase(v);
graph[v].erase(u);
dfs(u);
}
ans.push_back(v);
}
signed main() {
int t;
cin >> t;
while (t--) {
graph.clear();
ans.clear();
int n;
cin >> n;
map<int, int> p, v;
map<pair<int, int>, int> toIndex;
vector<pair<int, int>> part;
for (int i = 1; i <= n; ++i) {
int volume, pitch;
cin >> volume >> pitch;
toIndex[make_pair(volume, pitch)] = i;
if (p.count(pitch) == 0) {
p[pitch] = graph.size();
graph.push_back(set<int>());
part.push_back(make_pair(0, pitch));
}
if (v.count(volume) == 0) {
v[volume] = graph.size();
graph.push_back(set<int>());
part.push_back(make_pair(volume, 0));
}
graph[v[volume]].insert(p[pitch]);
graph[p[pitch]].insert(v[volume]);
}
int root = 0;
int cnt = 0;
for (int i = 0; i < graph.size(); ++i) {
if (graph[i].size() % 2 == 1) {
++cnt;
root = i;
}
}
dfs(root);
if (ans.size() != n + 1 || cnt > 2) {
cout << "NO" << endl;
continue;
}
vector<int> out;
for (int i = 0; i < n; ++i) {
auto p1 = part[ans[i]];
auto p2 = part[ans[i + 1]];
out.push_back(toIndex[make_pair(p1.first + p2.first, p1.second + p2.second)]);
if (out[i] == 0) {
out.clear();
break;
}
}
if (out.empty()) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
for (int i = 0; i < n; ++i) {
cout << out[i] << " ";
}
cout << endl;
}
}
return 0;
}
Editorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int f(int x, int y) {
return (x % y) + (y % x);
}
void Solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int ans = 0;
int mx = a[0];
for (int i = 0; i < n; ++i) {
ans = max(ans, f(mx, a[i]));
if (a[i] > mx) {
if (a[i] >= mx * 2) {
mx = a[i];
for (int j = 0; j < i; ++j) {
ans = max(ans, f(a[i], a[j]));
}
} else {
mx = a[i];
ans = mx;
}
}
cout << ans << ' ';
}
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
Solve();
}
return 0;
}








edit: fixed
I don't understand how E was accepted by coordinators since it is so standard to anyone who's ever seen Hierholzer's before.
What's wrong with the fun exercise in the div2 round?
It is not fun
The reduction is quite easy and then you need to copypaste template (which most people dont even have)
Also for no reason a[i] <= 1e9 so you need even more impl :)
This is only yours opinion)
mine as well
mine too
mine too. After contest, so many people tell me that E is a "template-problem".
Bro, why do you want to copypaste 15 lines of code?
Why would I not want to copypaste 15 lines of code?
You complain for bitset which is 1 line :)
bro once you do same for div 4 problem and now you are complaining quite contradictory
he hasn't authored a single div4 meanwhile
Honestly I couldn't find the reduction until the end. Maybe it's a skill issue on my side idk but I felt the idea was nice (maybe also because it's the first time I encounter something like that)
why its a fun?
The reduction definitely isn't easy, as you need to make a couple of observations to bring this task to the graph one. This greatly fits for the position of E
Put that in div4, I'll (begrudgingly) say it's just about OK. Div2, no.
ohh, we really didn't think about it, but you have opened our eyes to this problem. from now on, we won't make such mistakes again and will definitely take your opinion into consideration.
I think we can put this problem in Edu round to get more "fun".
Just a questions, How can people solve 2 prolems in a min?? Page loading itself takes 2 min for me. How is it possible?? Like 2 problems under a min. Reading problem and writing 2 problems in a min. Is it even possible??
Isn't the algorithm for directed graphs?
nah it works for both
I was not able to debug my code for finding Eulerian path, damn sed lyf :(
can u debug why my code is failing 321213790
2110D - Fewer Batteries can be solved without binary search too.
Solution is that ->
First for each index store the minimum batteries that will be required from that point so that one is able to reach the endpoint(nth node). That is done by dijisktra on the graph with opposite edge starting from node n and cost as maximum of all the nodes visited .
After that ,minimising the cost with normal dijisktra on forward graph starting with node 0 and cost as maximum of all the nodes visited.
U can look to my submission 321152832
I thought of this idea too before I realized that $$$s_i \lt t_i$$$
I used topological sort 2 times
Submission: 321166795
Complexity: O(2 * N)
The second topological sort isn't correct because you assume that in each node
vyou can have any number of batteries betweenl[v]andr[v]but this is not correct. Here is an example testcase where the solution fails.In the above example the problem is for node 3 you have
l[3] = 2r[3] = 10and you assume you can reach node 3 with 3 batteries and then walk the(3, 5)edge which has weight 3. However you can reach node 3 with either 2 or 10 batteries and nothing in between.Another thing which is interesting is that the two dijkstras solution also fails but with an output of 100, I explained why in one of the other replies.
Edit: Also, you don't need to manually toposort.
[1, 2, ..., n]is a valid toposort of the vertices since for each edge (u, v) is holds that u < v from the problem statement.Yo can you please elaborate how that works. Would be a great help
I did it in a similar way using Dijkstra's algorithm. But got MLE on test case 23. Can you please suggest me the changes i need to make in this code to get accepted? https://mirror.codeforces.com/contest/2110/submission/321131643
in your code: "if (minos[i] > v[1] + arr[i]) continue;"
isint that wrong? you cant just prune based off of that. you could have taken some more batteries before reaching the maximum edge in that path right? how are you certain that you can eliminate that path completely for finding minimax?
This lines assures that if the path i am going in is having current batteries less than the minimum required i shouldn't go to that path i.e doesn't minimise the maximum for that because since it has less batteries and I need minimum minos[i] to be able to reach the end , so I will not be able to reach the nth node with these batteries.
You are correct, it's indeed wrong.
if (w > v[1])is also wrong for the exact same reason. Here is an example where the solution breaks.In the above example the problem is that node 3 is first reached with 2 batteries and it's assumed the edge
(3, 5)which has weight 3 can not be traversed. However node 3 can also be reached with 10 batteries and this is optimal.damn nice i wasnt able to think of the first part cuz of that had to do some fluke binary search solution with dijkstra and now my accepted solution gives mle on 31
In the first dijkstra in your submission it seems like you can pop a not fully relaxed vertex from the queue. For example:
In the above imagine the edges in the transposition graph point to the left and you start your dijkstra from
(d, 0).Since the vertices you pop from the queue aren't necessarily fully relaxed as is the case with usual dijkstra this should have a higher time complexity.
Edit: I think the best way to avoid this is to use toposort as nithish654 explained in a reply.
Are you saying to keep visited array and all , i know that's how people usually write dijkstra but I prefer my way. As much as I know it only visited each node like maximum 2 times so usually works fine and usually keep a if check to avoid that but it is not necessary to do that.
No, your dijkstra seems fine implementation-wise, I am just saying that dijkstra in general wouldn't be efficient for finding the minimum number of batteries needed to reach the final vertex since you can't guarantee that the vertex with the smallest cost in the queue is fully relaxed. In some cases this will lead to rerunning dijkstra on part of the graph multiple times (not just 2 but up to
n. The above example I gave can be tweaked so that you addato the queueO(n)times and then each time you add it you run dijkstra on the subgraph to the left ofa) The problem is roughly the same as the problem with running dijkstra on a graph where some of the edges can have negative weights (but there is no negative cycle). Dijkstra can solve that problem but with bad time complexity.Problem F could also be solved in
O(N), tho it doesn't matter much. Most things are same, except there is one more observation: - Let's say our current array isa[1] <= a[2] <= a[3]... a[N]- Then, we don't actually need to tryf(a[i], a[N]), wherea[i] <= a[N-1]/2, sincemax possible value of f(a[i], a[N]) <= min possible value of f(a[N-1], a[N]). (wherea[i] * 2 <= a[N-1])Thus, if the maximum value gets updated (let's say
xis new,yis the old one):2*y > x, obviously answer= x.We check elements in range
y/2...y. (We can push everything to a set and just iterate from the back).Well, one can see that we only process an element with a current maximum only once, thus we can just push everything to a vector and clear after each use: 321161406
In question D many solution that were accepted shouldn't have passed system testing cause now that I am trying submit those same solution again they are giving MLE on test case 31 which those solutions were not tested against in the system testing phase!
+1
Test are added after system test,
My submission for D seems to be $$$\mathcal{O}(n^2)$$$ but there is no testcase to fail it. 321147941
For each node, I compute a list of intervals to describe all the possible battery counts at that node. Then computing these lists is a straightforward DP.
But for each transition between $$$u$$$ and $$$v$$$, $$$v$$$'s entire list must be checked. This motivates a hack testcase: for the first $$$\frac{n}{2}$$$ nodes, form a chain and attach each node to the middle node as well. Then for the other $$$\frac{n}{2}$$$ nodes, attach them to the middle node. The size of the middle node's list is $$$\frac{n}{2}$$$ now, and computing $$$\frac{n}{2}$$$ more transitions from that will give quadratic runtime. Here's the generator if I wasn't clear:
My final solution adds some optimization on top of the original idea, but with some work it can be defeated as well.
Is there a way to improve the worst bound for my approach?
Did anyone else get Runtime Error on test case 12 while solving E? How did you solve it?
why can dfs pass D?????? i tried many ways but not dfs till 01:30
It's really weird that my solution passed just with a
break. It does Dijkstra on $$$(idx,sum)$$$, which should be $$$O((n+m)W\log{n})$$$ in the worst case. Can anyone try to uphack it? 321125700resubmit your sol, it should give TLE/MLE now since there's test #31 and #32
Can anyone tell me why my solution is failing? It says that the jury found a solution, but I don't still can't see why my solution couldn't find the euler path, even after accounting for the euler cycle.
Problem E, -> Submission
This works too. (For D)
~~~~~
What is the reason behind DFS failing in test case #31 ?.
How one would have figured it out before implementing during contest that (Oh no DFS won't work need to figure out something else ...).
Hey for problem C my idea was at every point where there is -1 to check if the minimum element in the remaining array is smaller than or equal to current height.If yes , set that arr[i] to 0 otherwise 1. THen I later check if the given array is able to pass the array But on test 2 , number 89 this shows wrong.
Bro, exactly same problem happens with me. Idk why it fails, my logic seems to be correct so far. If anyone can help then please help us out.
My submission : 321127415
Because you didn't consider that if d[i] later equals 1
bruhh.. i did consider it using the num1 array which precomputes number of compulsory 1s in a range.. still its showing WA on pretest 2
My submission: 321158954
You can see my submission: 321099783
I get your idea.. but what's wrong with mine?
Can anyone help me out in finding a teat case were my code fails
https://mirror.codeforces.com/contest/2110/submission/321134907
Try this case:
1 2 -1 1 0 2 1 1
It should output 0 1
When you hit -1, you always choose to go up, which means you always fly at the height limit, but once you hit a 1 in this state, the programme will throw an wrong -1. like: 4 -1 -1 -1 1 0 1 0 1 0 1 0 1
thank you
Could you help me see why the time complexity is qualified? I used the priorityqueue and visit arrays,problem D:321109278
c&d are too easy, though I was stumbled by c because of an imperceptible mistake, which made my rating down
However, e&f are marvelous! I love them very much
Can anyone please help me out with why my code fails in pretest 2. (Submission : 321127415 )
My intuition is that I store the minimum of all upper limits among the limits from the end to the particular index i. So we only assign v[i]=1 when h<mini[i] because if we increase h when h is already >=mini[i], the answer would fail because we already exceeded the upper limit of atleast one obstacle. And if (h<mini[i]) , we can always keep increasing h by 1 (or assigning v[i] as 1) BECAUSE all the upper limits are at least mini[i] so we don't exceed anyone's upper limit and if we talk about exceeding the lower limit since we increase height by 1 now, it does not matter because being above the lower limit is still being in the range (li<=h<=ri) so we only have to worry abt not even reaching the lower limit of any one obstacle but since we keep increasing the height when v[i] has not yet reached mini[i], so we tend to reach the lower limits of obstacles as well cuz being above the lower limits(while being below the minimum of upper limits) is justified. So, I do not understand how it is still not an optimal path! :(
i too implemented the same logic , getting WA
Can anyone please help me out with why my code fails in pretest 2. 321158954
I store the minimum (along with its index) of all upper limits among the limits from the end to the particular index, and from the range of current index to maximum index of the minimum upper limit i count the number of compulsory 1s using precomputed num1 array in O(1). So we only assign v[i]=1 when h+(number of compulsory 1s)<mini[i] because if we increase h when h+(number of compulsory 1s) is already >=mini[i], the answer would fail because we already exceeded the upper limit of atleast one obstacle.
My code - ~~~~~
void solve(){
int n; cin >> n; v32 d(n), num1(n+1); vv32 p(n, v32(2)), minn(n, v32(2)); forn(i, n) cin >> d[i]; forn(i, n) cin >> p[i][0] >> p[i][1]; forn(i, n) num1[i+1] = num1[i]+(d[i] == 1); minn[n-1][0] = p[n-1][1]; minn[n-1][1] = n-1; rforn(i, n-2){ minn[i] = minn[i+1]; if(p[i][1] < minn[i][0]) minn[i][0] = p[i][1], minn[i][1] = i; } int curh = 0; forn(i, n){ if(d[i] >= 0){ curh += d[i]; if(curh < p[i][0] || curh > p[i][1]){ cout << "-1\n"; return; } } else { int diff = minn[i][0]-curh, ind = minn[i][1], ct1 = num1[ind]-num1[i]; // cout << diff << " " << ind << " " << ct1 << ln; if(ct1 < diff){ d[i] = 1; curh++; } else if(ct1 == diff) d[i] = 0; else { cout << "-1\n"; return; } if(curh < p[i][0] || curh > p[i][1]){ cout << "-1\n"; return; } } } print_vec(d);} ~~~~~
I could not understand your code or explanation , can you maybe explain a bit further , I can give you a simple rundown of the solution
In problem C i applied a greedy approach where i increase the height where ever it is possible .
firstly i calculated the maximum possible height for each obstacle such that i can reach the end .
then updated my values accordingly . can someone tell where can this greedy approach fail .
My submission — 321105467 ??
Consider this test case,
3
-1 -1 -1
0 10
0 10
0 1
Here, if you increase the height in both of the first 2 turns, you'll end up missing the third gate
What if we first do this: for every ri, we set it to the minimum of all rj where j >= i.
Then, if we increase the height whenever we can, we will not miss any gate's upper limit, and we will be able to clear the lower limits of all gates.
This sounds okay but this gives me wrong answer, I am yet to figure out why.
instead of minimum of all rj you can take minimum of extra 1's that rj can bear and then you can greedily increase height. like this 321309570
i dont increase hieght in both of the first two turns . i only increase in the first turn . in my ans vector i am storing the max permissiable hieght such that my height doesn't exceed the range in further turns . for this tc i would print 1 0 0 and i think thats not wrong ??
Consider this test case,
5
-1 -1 -1 1 1
0 1
0 2
0 3
0 3
0 3
If we increase the height in the first three obstacles, we will not pass in the last two.
Ohh right ! Thanks mate .
I had an alternate solution to B. I essentially cut the first opening bracket (always at first position) and last closing bracket (always at last position) and then checked if it was still balanced. It seemed easier to me that messing with the balanace factor arrays.
My initial idea in D was to binary search on the answer and run dijkstra(for each node, find max number of batteries you can end up with there) but that exceeds TL. But it seems like just bfs works: https://mirror.codeforces.com/contest/2110/submission/321128976
though it gets TL verdict after removing this line:
Cutting down on parallel entries seems to help a lot, but I don't think it makes up for the cases where each d[u] can be updated a lot of times. Can anyone prove the correctness of this or uphack it?
I don't understand why my solution for C is not working. Can anyone please help me out?
My Submission — 321200477
In problem C, I was able to write code to the determine whether the d array is possible or not, but couldn't do the build d array part. I saw some accepted submissions like #321209728 or 321058108. Either they choose greedily 0 as value for next d[i] or 1, it works. Why?
Using this submission as an example. What the author did was let the drone fly as high as possible (stick to the highest possible height to pass all obstacles).
If the program doesn't return -1, then it means there exists at least one possible path. Looking at how the array
Ris constructed, you'll see thatRis actually one of the possible paths. Because for anyi,R[i]is the height that1. achievable by the droneand2. can pass ith obstacles(because there exists at least one path). So you can just make the drone stick to heightsRand it will work.Actually,
if (hcur >= L[i - 1] && hcur <= R[i - 1])can just beif (hcur <= R[i - 1])and it's still correct, following the reason above. Hope it helps!In the solution to problem B, the last condition is useless, since we only removed the first opening bracket and the last closing bracket, so the final $$$bal$$$ will not change and will still be 0. After the loop, we can print "NO" without additional checks.
In B I was just checking for the presence of ")(" , where does this logic fail?
(()()) would break your code as you have )( in (( )( )) but the output here should be NO as removing any open-close bracket pair still keeps it balanced as the balance array is [1, 2, 1, 2, 1, 0] Which has no 0 except the last element (the logic used in the solution)
Did my first contest on codeforces. Got a rating of +438 and idk if its good or bad. I did 2 problems under an hour with no wrong submissions. For reference, I'm 1440 in codechef and 1442 in leetcode.
Here is an enhanced version of the problem F.
How to solve D if this condition
(si<ti)is not true?My solution for B. Can it be hacked?
We have string S, and I am finding such strings A and B such that A + B == S, A and B are balanced bracket sequence. A is ending with ')', B is starting with '('. I am deleting the first char of B, and the last char of A. So, if I found such string A and B, answer will be "yes", else "no"
Why is this solution incorrect: https://mirror.codeforces.com/contest/2110/submission/321230391
Can anyone give me a test case where this fails?
1
4
-1 -1 -1 1
0 2
0 2
0 2
1 2
A valid solution 0 0 0 1 exists but yours give -1
what am I doing wrong in problem C? this is my intuition
I thought since we can only increase the height and can't decrease it later on, I will find the suffix minimum for the r[i] values from end to start, so in our current state we will know how much we can increase, so that later on we will be safe. So I will stick to the max possible answer at the current state, and hopefully this should satisfy the current l[i]; if it's not, then it's not possible.
1
5
-1 -1 -1 1 1
0 1
0 2
0 3
0 3
0 3
your code gives -1 while we can get an answer . i did the same mistake we cant always increase the height because we need to consider the further turns where d[i]= 1
Oh thanks I got that, btw how did you find this test case, you worked on this or is there any way to fetch the failed cases ?
someone helped me in the comments :) . but it seems so obvious now i feel stupid :|.
nice
Fashionable array can also be done without sorting, hence reducing the time taken to sort...
can C be solvable using dp? any idea how?
The first time I participated in a CF match, I failed in c because TLE with dfs
Can someone please tell why does this fail for C: Racing Submission : https://mirror.codeforces.com/contest/2110/submission/321334485.
Here i'm maintinig the maximum it can climb up for each i, and I'm taking the future d[i]'s into account. So test cases like these are passing :
1
4
-1 -1 -1 1
0 2
0 2
0 2
1 2
or
1
5
-1 -1 -1 1 1
0 1
0 2
0 3
0 3
0 3
For B i ended up counting the number of independent perfect bracket sequences that are in the string, for example: ()(()) -> has two '()' and '(())' and if we event encounter that such independent prefect bracket sequences are present then the ans would always be YES and otherwise NO. 321348376
Hi! I agree that if the sequence has at least two independent balanced bracket sequences, the answer would be yes (like how you showed it). However, to show that your solution is correct, you'll have to prove the "otherwise" part. Because $$$A \Rightarrow B$$$ does not imply $$$\neg A \Rightarrow \neg B$$$. (Explained here).
But I did the same thing as you!
Cool :)
As a tester, I have a proof that upvoting this comment will lead to positive delta. But the proof is too long to fit the margin.
No way I spent like 3 hours solving B problem. But eventually did it by myself.
Thank you for Editorial !
Can someone help me in fixing this? I've no clue why this won't work. I know that there is a simpler reduced version of the dijkstra based off the constraint $$$ u_i \lt v_i $$$ but I wanna know what's wrong here...
Submission
Need help
For Problem C(Racing), my solution says "wrong ans on test case: 2". I couldn't find my mistake. For which case scenario, my solution might not work properly? I am genuinely seeking help, please don't down-vote me.
Here is my submission: https://mirror.codeforces.com/contest/2110/submission/321800281
Hey, I think you are incrementing height in a not so good way. By the way, your cinn and print macros are cool. Let's consider this test case.
1
3
-1 -1 1
0 2
0 2
0 2
Here your test performs hi = 1, then 2, but at 3rd step it got stuck as now it had to increase mandatorily. So, it outputs -1 but answer do exist 0 0 1 or 0 1 1 or 1 0 1.
Hope it helps!
Hello , In Problem C , can anyone tell that why my code is not working -- it is giving error in test case 2 My submission --
here is my submission link as well -- https://mirror.codeforces.com/contest/2110/my I would be grateful if anyone helps me out with this .
it seems that I found an $$$O(n+m)$$$ dp solution for D?
first, for every node, find how many batteries we need at least to reach node n. second, for every node, find the minimum count of batteries we should use to reach current node, and the maximum count of batteries we can collect before we leave current node. using these info, we can know the final answer.
is it completely correct? my accepted submission
i also did it with just 2 O(n + m) dps
My solution to D that passed (and still passes) is brute force and can reach O(2^sqrt(M)) for a complete graph. 321117884
I hadn't even seen that the edges go up in value in the competition, shit happens
Anyone knows why this solution for problem B (Down with Brackets) works? I basically check if the entire sequence (i.e., String $$$S$$$) has at least two balanced sequences that are concatenated.
Hi! I did the same thing (submission). The logic we used in the solution is the same as in the editorial, it's just implemented in different ways.
The editorial essentially says: let a balanced bracket sequence be constructed using steps
S1, S2, S3, ... Sn. Then the sequence cannot be made unbalanced if and only if the last stepSnis of type 2 in the formal grammar.Our solutions simply check for the above fact. If the last step is of type 2 in the formal grammar, then
cnt >= 1holds until you process the last character. On the other hand,cntwould reach 0 in the middle at least once, and another time after you've processed the entire sequence (since it's balanced initially). Then you would haveseg > 1, thus the sequence can be made unbalanced.I'm just starting out on CF, but could anyone help me understand how the editorial of Problem 2110C — Racing translate into the code that's given?
PLZ PLZ PLZ explain me where my code is failing in C(RACING) it is giving wrong ans on test 2 in test case 474 https://mirror.codeforces.com/contest/2110/submission/322820237 .. my logic is doing all -1 1 and store indexes in stack ( dont store those indexes where doind -1 into 1 is a necessity) and when h > r .. take the indexes of stack and make it 0 .. can u read the code and tell the failure test case please
https://mirror.codeforces.com/contest/2110/submission/323352665 You didn't check that you didn't break anything before(the second loop in the fix). And I think you need to add current -1 to stack before removing from stack, or at least I understand that it works if you do it this way
Can you help me identify what is wrong with my code? Submission: https://mirror.codeforces.com/contest/2110/submission/324044502 It fails on test case 2 (7).
.
is there any recursive solution to D? not by iterative dp.
.
Hello I am having trouble to get the idea on how the min(i-1 and j-1 ) will be the answer on fashionable arrays.. and the test case 8 the right seems to cross the left? in the sorted array kindly help
how strong intuition needed to solve F
F is amazing! I can't see any of these three facts.
F is a really beautiful problem