We will hold AtCoder Beginner Contest 237.
- Contest URL: https://atcoder.jp/contests/abc237
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20220130T2100&p1=248
- Duration: 100 minutes
- Number of Tasks: 8
- Writer: leaf1415, math957963, sugarrr, YoshikaMiyafuji
- Tester: kyopro_friends, Nyaan
- Rated range: ~ 1999
- The point values will be 100-200-300-400-500-500-600-600.
We are looking forward to your participation!
for D I created binary tree and did inorder traversal on it. I'm sure there's better approach for it.
You process the queries backwards and see what will happen!
Yes I did this way : link
Linked Lists can also be used to solve this. Submission
Note that the STL list provides the method pos=lis.insert(pos,int) which is all we need.
example submission
Recursion is also a very good way to solve the problem.See this submission for more details.
PS: This code isn't written by me.
I don't know if it's a bug in atcoder or the problem was updated, but I got the statement for problem D as problem B at first before I reloaded: https://imgur.com/a/FFEzsaY
ya it happened with me as well.
I know I was wondering why it's taking me longer to do B.
Same for me, one wrong submission.
Check the clarifications tab.
If you have submitted the answer to question D to question B, please contact us through the clarification tab within 5 minutes after the contest ends. We will delete your submission.
My bad, I didn't see clarification at that time.
Can somebody explain why a super simple bfs in E does not TLE?
Edit: In example this submission
Simple BFS worked for E ? :( I had to do Bellman Ford to solve it My Code with Bellman Ford
I used max Dijkstra
I thought of using it then remembered it does not handle negative edges so Thought of using this
negative edges are ok, but not negative cycles. And there are no negative cycles as this would be physically impossible
Why are negative edges ok but not negative cycles? Doesn't dijkstra work because before processing vertex v, we have already processed all vertices with distance smaller that distance to v, and negative edges would break this
Depends on your implementation, if you allow to visit a node more than once you will be fine. The runtime analysis is then a bit more complicated, but I believe it should better than Bellman Ford, as latter will do the maximum amount of iterations possible, while Dijkstra might stop earlier..
How did you do bellman Ford? It's n^2 right. And how are dijkstra solution passing for E. :(. There are negative edge weights. It should fail!!
Negate the costs https://atcoder.jp/contests/abc237/submissions/28945458
Doesn't matter, even if you negate, positives become negative, and negative become positive. Still negative will be present.
The problem with dijkstra in a graph that has negative edges, even if it doesn't have negative cycles, is that it works slower. I make an optimization in the dijkstra that is: when I remove a node from the priority queue, I mark it, so as not to calculate it again in the future.
This works because this algorithm is greedy, and since the node that I remove from the priority queue at a given moment, I will not be able to update it in the future, because all the nodes that I analyze later will have a distance from the initial node greater than its distance. This would fail in a graph with some negative edge. The algorithm itself would work as long as there are no negative cycles.
In this problem there is no difficulty of any kind with negative edges since we want to maximize the distance, so edges with negative weights do not suit us.
Your code fails for testcase added after contest
https://atcoder.jp/contests/abc237/submissions/28970593
Thanks. I realized that I was lucky. Now, I saw a Tweet and followed the advice to change priority queue to queue. Then the after contest test passes: submission
The Tweet says AtCoder should add one more after contest test case so that changing PQ to queue still TLE.
The final happiness ending at node i can be viewed as (Initial height — final height) — All the edges where you travelled upwards. So make a graph where upward edges have positive weights and the downward edges have weight zero. Find minimum distance for each node from node 1. Submission
Let dp[v] be maximum happiness reaching vertex v.
We initialize dp with negative inf and dp[1] = 0.
Let's say we have an edge between vertex 1 and 2, and {height of 1} < {height of 2}.
When we're updating vertex 1's neighbors,
The second one is obviously bigger since we set all values to -inf by default, and therefore values can be calculate with dijkstra's.
My submission
It fails with new testcase
The while() cycle does what a normal while() in bfs does — goes over all nodes, so O(n) from here. For every node, we traverse all its edges and since every edge has two endpoints, this means we get O(2M) iterations from here. So all in all we get a complexity of O(n + 2m). Hope that helped!
I think it's SPFA, Shortest Path Fast Algorithm. It will run in approximately O(N + M). It doesn't get TL because it's hard to construct a good graph.
Thanks for pointing that out. Actually, that is what I referred to as "super simple bfs". It looks like dijkstra but with a simple queue instead of a priority queue.
And also the problem with this is described in the article, its worst case complexity is like Bellman-Ford, so would TLE.
On the other hand, the way the tree is constructed makes to edge weights not arbitrary, they obviously determine each other. It seems that this makes the simple algorythm work.
Which, frankly said, makes the problem a bad one. Given the fact that this is a beginner contest, we can assume that a lot, maybe the most partitipants who solved it did not because beeing smart enough to see that.
Me after solving A,B,C,D,E
Translation : It's not my zone of expertise, I am out.
Can anyone explain their approach for F as editorial is not published for now.
I solved F with DP, so
dp[i][j][k][l]
can count the number of sequences up to the ith number, where LIS of length 1 end withj
, LIS of length 2 end withk
and LIS of length 3 end withl
. In each of these states you can iterate through all numbers 1,..,m, and either make one numberj
,k
orl
smaller or we are not allowed to use it (as greater than currentl
)So there are n*m^3 states and each state needs O(m) -> O(n*m^4) = O(1000*10000) = O(10.000.000)
If you use a bitmask to maintain the young diagram . You can know the number of sequence which LIS is k (k<=m) in O(n2^m).
my solution: https://atcoder.jp/contests/abc237/submissions/28953647
Is this a standard technique? If yes, can you provide resources (problems, or a blog-post) on it?
I only found this (in Chinese).
Gary2005 your approach is lit....
Just amazed me as for LIS upto M you just only have to change if condition of popcount==3 to popcount==LIS and solution Time complexity is independent of LIS length required henced amazed me great Approach. Thankyou For sharing....
plz explain E same for me after doing 4 only also tell some resourses for graphs
Do max dijkstra My previous comment
Ex and div1f of last round are exactly the same problem.(After building the graph)
Excuse me, which round? Do you mean that the algorithms or the tricks are the same, or something else?
UPD: I see. Thank you very much.
https://codeforces.me/contest/1630/problem/F
problem G
Actually it can be solved much easily using just 3 lazy segtrees, as we just need to keep track of number X(say 1), and numbers smaller than X(say 0) and bigger than X(say 2).
It can be solved using 1 lazy segment tree, and just keeping track of the index of $$$x$$$ after every query.
My submission
Can you share your submission for that? I think I am too stupid to get this blog-post :(
Anyone with Top Down approach for F ? It will be great if you can share your code
topdown
Arigato :D
if(curIdx == n && rd != m+1) return ans = 1; if(curIdx==n) return 0; can u plz explaint these lines?
Hey mate,
I used
m+1
as dummy value, when therd
( meaning the smallest end of a LIS of length three — naming is bad here) is stillm+1
, we don't have no LIS of length 3.For example, If you choose 123 you will have
fst = 1
,snd = 2
andrd = 3
. However if you have 111 you will havefst = 1
,snd = m+1
andrd = m=1
, meaning you only have a LIS of length 1.Not sure how the others implemented it. For me this felt the most natural.
I solved Ex using a greedy maximal clique solution.
why don't atcoder amalgamate test cases like cf and cc it will be easier to copy and check on local compilers
The editorial is available in Japanese but not in English. Maybe there is just a script to run to make it available ?
The sample solution are written in C++ or Java or Python. Those are still readable without knowing Japanese.
can someone explain problem e solution plz
see above
Note that also a simple bfs works fine. I am still not sure if this is caused by the construction of the tree, or weak tests.
When will be the editorials posted? It has not been posted yet.
I translated them myself: https://atcoder.jp/contests/abc237/editorial/3347
Since official English editorials never arrived, I translated all Japanese editorials myself. They are brief and not word-to-word precise, more like my own restatement of the official solution. Hope it helps.
https://atcoder.jp/contests/abc237/editorial/3347
In order to understand G, I spent 2 days now reading the segment-tree for sorting subsequences and I still didn't really get it. Now I read your translation, and after 2 mins I got it. Thanks a lot & well done :)
can someone tell why max Dijkstra on problem E getting TLE?
My submission