| Show all threads Hide all threads Show all messages Hide all messages |
| You can use a segment tree for brace balance checking | Levon Oganesyan | 1574. Mathematicians and brackets | 8 Jun 2026 21:12 | 2 |
Tree for minimum is enough. It's O(N) problem with O(1) memory (apart from string itself) |
| best tests | Dmi3Molodov | 1800. Murphy's Law | 8 Jun 2026 21:02 | 1 |
It is much more interesting to look for good tests for this task than just to solve it. Here is the AC program (with a small error in order not to publish solutions). I will look for where it will fail. #include<iostream> #include<cmath>//too lazy to write sqrt() yourself int main() { unsigned l, h, o; std::cin>>l>>h>>o; unsigned phase = 0; if(l<h*2) phase = o*sqrt((2*h-l)/981)/15+1; char const*answer[]{"Butter","Bread\n"}; std::cout<<answer[(phase>>1)&1]<<std::endl; } |
| Answer can be negative | Igor Parfenov | 1300. Taxes | 8 Jun 2026 17:06 | 1 |
Input 0 50 10 0 0 100 200 -1 Output -5.00 I thought at first, that an absolute value has to be printed, which gets WA 3. |
| Could anyone provide me with an O(n) solution? My works O(n log(n)) | Sq1 | 1651. Shortest Subchain | 8 Jun 2026 15:30 | 2 |
Could anyone provide me with an O(n) solution? My works O(n log(n)) BFS for shortest path, but not over original graph - over the chain itself. There are edges of weight 1 and 0. |
| Accepted 0.156 2 993 КБ | TakeOver | 1067. Disk Tree | 7 Jun 2026 23:42 | 4 |
Just used STL contaners such as std::map<std::string,T>, std::vector<T>. :) 33 lines of code. what is "T"? give please full description. I used a map and a set. My time was a little less than 2 times faster, and used a little more than 2 times more memory. struct dir { std::string name; std::map<std::string, dir*> children_items; std::set<std::string> children_names; }; The set gives you the sorted list. The map gives you instant access to a subdirectory of a given directory by name (taken from the set) Edited by author 29.12.2022 02:15 struct dir { map<string, dir> sub; } root; |
| WA test 8 | Henrique | 1588. Jamaica | 7 Jun 2026 02:24 | 3 |
plz help me, i got WA on this test , if someone knows this one help me!. I think it's a test like: 3 0 0 0 3 0 2 and I just adjust my program I did it using integers keeping unique lines (a,b,c) a*x+b*y=c so that gcd(a,b)=1, a>=0. Mistake for WA8 was that for a=0 I did not ensure b>0, i.e. (0,1,1) and (0,-1,1) were considered as different lines. |
| Better algorithm | LLM_AI_Testing | 1553. Caves and Tunnels | 6 Jun 2026 21:23 | 1 |
Use heavy-light decomposition: after O(N) preprocessing, every tree path becomes O(log N) contiguous ranges in the HLD order. Because cave radiation only increases, maintain range maximums with a monotone Fenwick tree, giving O(log N) per update and O(log^2 N) per path query with O(N) memory. Current #1 AC Edited by author 06.06.2026 21:24 Edited by author 06.06.2026 21:24 |
| Good test | Yermak | 1312. Tray | 4 Jun 2026 15:25 | 2 |
600 400 152 63 152 Solution exists. |
| AC at least, but for me this problem very strange! | xurshid_n | 1553. Caves and Tunnels | 4 Jun 2026 12:33 | 3 |
Heavy-Light-Decomposition -> GOOD data structure! thank you all! sqrt(n) decomposition also works here (0.5 sec) and easier to implement it's actually does not differ much because heavy-light with segment/fenvick over chains will be something like Q*log^2(N) with bad constant over it Actually it was the other way around :) except for ram usage SQRT: 0.437 11 532 KB HLD: 0.296 14 784 KB |
| Stack Overflow | Night | 1553. Caves and Tunnels | 4 Jun 2026 11:33 | 4 |
Please I got Crash(Stack Overflow), I implemented my first heavy-light descomposition and tried this problem, but I got this. I got AC, I had to convert the DFS to BFS, to evade the StackOverflow. Edited by author 02.11.2011 04:45 Edited by author 02.11.2011 07:20 Edited by author 02.11.2011 08:20 {$m 100000000000000000000} You can use "G++ 9.2 x64" language to avoid it You can also use #pragma comment(linker, "/STACK:16777216) for MSVC and both heavy-light or sqrt decompositions can be performed with BFS, so no recursion needed |
| Hint for WA #8 | Vedernikoff 'Goryinyich' Sergey (HSE: АОП) | 1524. Men in Black | 3 Jun 2026 22:56 | 1 |
Hint for WA #8 Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 3 Jun 2026 22:56 Likely some rounding issue, e.g. in Python int(x + 0.5) => WA #8 int(x + 0.5 + 1e-9) => AC |
| hints (Nostradamus advised this) | Dmi3Molodov | 1401. Gamers | 3 Jun 2026 16:47 | 1 |
using u32=unsigned; u32 constexpr M = 9; u32 n = 0, g[1<<2*M]; template<u32>void solve(u32, u32=0); template<>void solve<2>(u32 voidXY, u32 BaseXY){ u32 e = n++, *p = g+BaseXY, q = g[voidXY]; *p = e, p[1] = e, p += 1<<M, *p = e, p[1] = e, g[voidXY] = q; } template<u32 s> void solve(u32 V, u32 B){ auto constexpr f = solve<s/2>; u32 constexpr m = (1<<M)-1; bool a = (V&~m)<(B&~m)+(s<<M)/2; bool b = (V&+m)<(B&+m)+s/2; f(V, B+(!a)*(s<<M)/2+(!b)*s/2); f(B-a*(1<<M)+b+((s<<M)+s)/2-1, B-a*(s<<(M-1))+b*s/2+(s<<M)/2); f(B+a*(1<<M)+((s<<M)+s)/2-(1<<M)-1, B+a*(s<<M)/2); f(B+a*(1<<M)+((s<<M)+s)/2-(1<<M), B+a*(s<<M)/2+s/2); u32*c = g+((s<<M)+s)/2-(1<<M)+B; c[m+(b&!a)] = c[(a&b)-1] = c[a<<M] = n++; } //this is a very funny, but working program code. Edited by author 03.06.2026 19:49 |
| WA #3 | 👨🏻💻 Spatarel Dan Constantin | 2139. Experiment with Juice | 2 Jun 2026 03:13 | 1 |
WA #3 👨🏻💻 Spatarel Dan Constantin 2 Jun 2026 03:13 Input: 3 -6 -9 9 -1 0 5 1.5 -5.0 2 -155 -292 Output: 11.571429 0.000000 0.000000 |
| TL 17 | ~'Yamca`~ | 1623. Fractal Labyrinth | 1 Jun 2026 23:09 | 1 |
TL 17 ~'Yamca`~ 1 Jun 2026 23:09 you can decompose path (i -> j) like (i -> x) + (x -> y) + (y -> j) or like (i -> y) + (y -> j) |
| Tests | 👨🏻💻 Spatarel Dan Constantin | 1909. Space Recon | 1 Jun 2026 18:42 | 1 |
Tests 👨🏻💻 Spatarel Dan Constantin 1 Jun 2026 18:42 WA #13: 2 -4 -2 2 10 10 4 -2 -6 -4 1 -3 10 > Warning WA #53-58: 987 887 165 624 -588 687 71 516 -557 926 960 882 836 > False alarm WA #75: -14293 4710 59090 99004 48305 96853 -727 -55911 60157 -71916 -57144 -62493 2339 > Warning Edited by author 01.06.2026 22:05 |
| physically incorrect tests | Dmi3Molodov | 1930. Ivan's Car | 31 May 2026 02:21 | 1 |
Explain example number two. How can you always move up or always down and arrive at the starting point? It's impossible!!! |
| Good problem! | Felix_Mate | 1752. Tree 2 | 30 May 2026 14:16 | 6 |
I got AC with O(N*sqrt(N)),but my solution is very hard(274 lines and many different subtasks). Who can say simple solution(idea without code)? Hi. This is my solution for this problem. Let's find two farthest nodes in tree. Let's call it f1 and f2. It can be done by two bfs'. Now let's answer for queries. Let the y farthest node from x(it's f1 or f2). If such node exists that dist(x, z) = d, then it would lie on path from x to y. If dist(x, y) < d, answer would be 0. Let l be lca(x, y). If dist(l, x) <= d, answer would be dist(l, x)'th parent of x. If x is ancestor of y, answer would be (dist(x, y) - d)'th parent of y. Otherwise answer would be dist(l, y) - (d - dist(l, x)). Sorry for my poor English. O(N*log(N)), ~100 lines of code, ~1K gzipped For every edge out of a node we calculate L, the length of the longest path from this node thru the edge. It is two DFS: the first one to calculate L for downward edges, the second one to fix the upward edges. At most two edges (with the largest L) of each node are needed to calculate the longest paths (the second is needed for the situations where we get from node A into node B and in node B the edge B->A has the maximal L). For these two edges we precalculate short-cuts: for all i, such that 2^i ≤ L, we save the node C that can be reached after 2^i steps and from which edge in C it was reached. My solution is quite simple, just find one farthest nodes pair in the tree by two DFSs, denoting f1 and f2. Then use f1 as root and dfs to calculate the 2^i steps' father of every node x. And use f2 as root similarly. Then the answer can be done by express d to the binary form and jump at most log(n) to find an answer under these two roots. We can actually solve it on just O(N) time. Let's set vertex 1 as a root. Now let's at first find the depths of subtree of each vertex, deepest vertex in each subtree and the distance from the root for each vertex. This can be done in one DFS. Let's name them as: 1) depth[ver] -> depth of a subtree of vertex ver 2) dist[ver] -> distance from vertex 1 to vertex ver 3) mx_ver[ver] -> deepest vertex in a subtree of vertex ver Now we can check for all queries: 1) If query is (v, d) and depth of vertex v is >= d, then the answer is the parent of vertex mx_ver[v] on distance (depth[v] - d) (so we should somehow later go up from vertex v to (depth[v] - d) edges). Let's store it in mx_ver[v]. 2) If query is (v, d) and distance from root to v >= d (so dst[v] >= d), then the answer is the parent of vertex v on distance d, let's store this information in vertex v. What should we do with all the other queries? All other queries (v, d) tell us that the answer for them will look somehow like this: Take vertex v, go up several edges, then go down to some other subtree. So we need to take some ancestor of v and go into it to a subtree different from a subtree containing vertex v. Let's say that this ancestor is some vertex u and the depth of its deepest subtree not containing v is H. Then if (dst[v] - dst[u] + H) >= d, we can choose u as a suitable ancestor. And the answer for the query will be the parent of the deepest vertex in subtree H on distance d - (dst[v] - dst[u] + H). Great thing about these formulas is that if we stay in some vertex v during some DFS, for all our ancestors the number (H - dst[u]) is a constant and we can keep the maximum value of it on current path. So what should we do next? Let's simply run one more DFS. During our walk through the tree in the DFS let's keep maximum value of (H - dst[u]) for all our ancestors. To do this we need to do some routine stuff: 1) Calculate two maximums by depth[to] + 1 for all children (if we will go to the subtree with first maximum, we will use H - dst from the second one). 2) Before going into some child check if the new found values are larger then global maximum (H - dst[u]). 3) Not forget to carefully restore this global maximum going up on each step. 4) Each time we take new maximum for (H - dst[u]), also store the deepest vertex in the subtree H. Then in each vertex during this DFS we also need to iterate through all remaining queries for this vertex and try to set an answer to them, again in form "Answer for this query is a parent of some deepest vertex in some subtree H on distance (dst[v] + (H - dst[u])) - d" The final step would be to run one more DFS and in all vertices with stored info "go up to distance X" do this by simply storing current DFS path and writing needed parent as an answer for the corresponding query. |
| why i have Runtime error (stack overflow) with Visual C++ x64, but AC with G++ 9.2? | >>> | 1752. Tree 2 | 30 May 2026 14:13 | 2 |
Why is there such a big difference between these two compilers and how do I know if I have solved this problem, it just feels like I wrote really dirty code and it somehow worked. #pragma comment(linker, "/STACK:16777216") |
| WA #23 | 👨🏻💻 Spatarel Dan Constantin | 1616. Square Country 4 | 29 May 2026 23:58 | 1 |
WA #23 👨🏻💻 Spatarel Dan Constantin 29 May 2026 23:58 In test 23 the alpha angle is very close to 0 or 90. |
| If WA#6 | Timur Sitdikov (MSU Tashkent) | 1637. Triangle Game 2 | 29 May 2026 13:48 | 2 |
If WA#6 Timur Sitdikov (MSU Tashkent) 8 Jul 2011 11:43 Try this: 0 0 1 0 0 2 0 0 -1 0 0 -2 2 Re: If WA#6 👨🏻💻 Spatarel Dan Constantin 29 May 2026 13:48 Input: 1 1 5 1 4 2 -1 -1 3 -1 2 -2 Output: 3 |