Common BoardIt turned out, that totally incorrect implementation can pass all previous tests in discussions. Input 3 0 0 5 10 0 5 2 4 5 Output 6 Edited by author 08.07.2026 19:22 just read some titles abot hanoi tower and learn some algorithm like floyd and u 100% will can solve this problem no need for BFS, simple O(N) cpu, O(1) ram solution If I enter for example 150000 I get overflow , (y-1)x^5 passes limitation of any type. Do I need to create new type to keep ((10^8)^5)size value ? Or anything else I have to do with values, expression? I solved it with that g-function. int g(int x, int y, long long m=9973){ long long lx=x, ly=y, lx2=(lx*lx)%m, lx3=(lx*lx2)%m, lx5=(lx2*lx3)%m; return ( ((ly-1)*lx5)%m + lx3 - (lx*ly)%m + (3*lx)%m + (7*ly)%m) % m; } You don't need long long if all inputs are within 9973 What is the test #29? Can anybody give me test for WA #29??? Will anybody answer my question??? Will anybody answer my question??? Maybe in year or two. Forum is not for instant answers. It is rather knowledge base. There is no answer to your question in the base yet. Maybe answer will appear but 99% that _you_ will first find the bug and post yourself test for the bug here than someone get wa29 and post test for it. At last, I've solved it)))) If you have WA29 try this test: 8 6 1 2 5 4 1 2 1 6 1 2 1 2 3 1 2 4 1 5 6 1 6 7 1 6 8 1 Answer is : 13 3 3 2 4 Edited by author 28.06.2026 08:01 I suspect (but still not sure) that this problem is not solvable, and you have to implement the same incorrect solution, as author did. do not use many nodes if there is no path between them! PLEASE... It is necessary to compare the speeds of algorithms for finding an existing path, rather than the speeds of algorithms for finding the fact that there is no path. P.S. And the computing capabilities of the russian Anka are simply amazing! :-) It is not written in the statement explicitly, but the solution has to be non-precise. The epsilon can be determined only by random submissions. It is possible to solve the problem 100% precisely, using only integers, but it will give WA 4. Thank you! I used EPS = 1e-2 and got WA #49 I used EPS = 1e-3 and got AC There is this sentence in the problem statement: "The coordinates are accurate to 0.0001." This makes me think EPS should be larger than 1e-4. How much larger? Hard to tell without submitting. Also, this sentence makes me think that the coordinates are not precise, therefore a solution using only integers would be expected to fail. One more thing: Since it's guaranteed that at least one solution always exists, I believe the only case where EPS = 1e-2 / EPS = 1e-3 can make a difference is the N = 2 case. Where can I exchange those 3332 Rubicoins I have been mining for 6 hours 20 minutes? Hint: don't forget to use multiple CPU cores and compile with optimizations. My solution produces an automaton with 2n^2 + n states, but what is the smallest possible size? Is it still ~n^2? Edited by author 14.02.2024 16:19 My solution produces an automaton with exactly 2n^2 + 1 states. Can it be done better? I don't know, but if I had to guess, I would say no. However, for a particular input automaton, some of the states of the output automaton may be unaccessible, thus they could be removed and the problem could be solved with even fewer states. But, there are input automatons where all the states of the output automaton are accessible, thus the upper limit of my solution is 2n^2 + 1 states on the worst case. What's special in test 7 ? I tried all the tests given here and I get right answer. My algorithm is to use bfs to calculate shortest path from source to each destination. If destination is reachable, source is updated to destination else source remains same. Anything wrong with my method ? may be some problems with precision? I got the same problem .. i have WA7 .. I used BFs .. O(n*m*k) with 2 quest .. one for the blocks whose were reached by vertical or orizontal moves ( last move ) and another for those who were reached with diagonal moves (last move counts only again .. ) with this i do not need to use Heap :( but i got a problem .. i triend almoast every test .. and they worked .. but still WA7 .. :( my prog. it's not written so well ... so i will not post it .. if you think that it will help you .. ask for it : ) i will keep in touch with this thread :-S I tried it this way - i.e. propagate all with 1, then with sqrt(2) from current frontier to upcoming edges, but here is the thing: distance 0 leads to 1 and 1.4 (all still fine and sorted) distance 1 leads to 2 and 2.4 (all still fine and sorted) distance 1.4 leads to 2.4 and 2.8 (all still fine and sorted) distance 2 leads to 3 and 3.4 (all still fine and sorted) distance 2.4 leads to 3.4 and 3.8 (all still fine and sorted) distance 2.8 leads to 3.0 and 4.2 (WOOPS! - 3.0 will be placed after 3.4 and 3.8) so I did Dijkstra, but with super-optimization. Instead keeping all nodes in a heap, I kept a heap on unique distances (as of A+B*sqrt(2)), and for each such distance I kept bidirectional list of nodes with that distance as currently reached. This makes edge relaxation O(1) - remove from current list, and add to another. So it's O(N*M)+O(K*log(K)) where K is number of different distances, and there are not so much on the way. Although I checked with asserts, there are cases when you have like 8 or even 16 upcoming frontiers even during first 6 tests. Relexations start happening with test 5, but only test 7 leads to WA on them with too greedy approach. Edited by author 24.06.2026 11:43 Why for D = 8 answer is 10? Why 9 is not answer ? indexes : 0 1 2 3 4 5 6 7 8 9 10 prefix-sum of a[1..10]: 0 7 11 18 18 23 29 33 37 42 46 prefix-sum of b[1..10]: 0 5 8 13 14 16 19 22 29 31 31 diff : 0 2 3 5 4 7 10 11 8 11 15 t = 9, diff 11, t = 10 diff = 15 and minimum t which diff >8 is 9. a,b=map(int, input().split()) if a==1: print(2) exit() if (a*2)//b<a*2/b: print(a*2//b+1) else: print(a*2//b) Edited by author 23.06.2026 16:44 when trying to update from (ux,uy) to (vx,vy) i was checking if (vx,vy) was already popped from priority_queue. this got me wa 22 many times. later, just out of frustation i removed the check and let (vx,vy) be updated even after it was once popped. and u know what, mysteriously got AC. of course, there has to be some logical explanation behind that. please explain anyone? Thanks in advance. I followed by your advice, and also suprised! Consider this test 4 5 1 1 4 5 11111 22221 21111 22222 You may get caught by situation that '2' at (3,1) gets way longer walking path from '1' at (3,2) than from '2' at (2,1). I remedied this by traversing both fronts in parallel, so it's still O(N*M) BFS w/o heaps or sorting. Edited by author 23.06.2026 21:29 4 1 3 1 4 2 4 1 2 4 The correct answer is 1. Thanks :) Forgot to traverse ALL cities between L and R Hint: convert first tree some middle special case tree , and from this make isomorph to target tree. Thanks!!! Had the same problem at the beginning, but finally solved it. Good test that helped me to find a bug in my algorithm was: 3 6 2 1 5 When the solution is: 2 (not 3) 2 5 1 Edited by author 24.03.2014 16:32 Edited by author 24.03.2014 16:33 Why two? need to output the maximum amount of trips of the elevator. I dont understand it. Because you can't get three trips here no matter the ordering Can be solved using two DFS calls and tree rerooting in O(N) while maintaining a DP array where DP[node] = sum for all paths from node to all the nodes in its subtree (considering 1 as the initial root). Tree rerooting can be used to calculate the sum for all nodes. It's easier to solve by counting in how many paths each edge participates which is v*(n-v) if 'v' is number of nodes in its subtree. So just BFS is enough to get topological order to calc these amounts. Hi all. I use dfs to find the number of connected components. If there are 2 components,then i output each of them as a single team.If there is only 1 CC,then i output numbers from 1 to n/2 and from n/2+1 to n. Otherwise "No solution". It seems to me correct,but.... Or tell me some tests that prove my idea's fail) Your idea is incorrect. 1) If 1st person knows 2nd person it doesn't mean that 2nd person knows 1st person. 2) If 1st and 2nd persons know each other and 1st and 3rd persons also know each other it doesn't mean that 2nd person knows 3rd person and vice versa. According to your algo in the first case both persons will be in one connected component, and in the second case all 3 persons will be in one connected component. Hi, I think that you should find the strongest connected components in a digraph. No, it's about finding two cliques If you use Aho-Korasik+DP you should delete forbidden words which contain other forbidden words. Example: alphabet = "01" forbidden words = ["100", "10", "11"] -> forbidden words = ["10", "11"] Aho-Corasick has "dictionary" edges for this purpose, so if bad[suffix[i]]==true, then bad[i]=true. Ignoring words that contain other words also works, but it's not true O(N) :) and there is pitfall of some word like "AB" being listed twice and cancelling itself out, so if you go checking for substrings, make sure that the other word is strictly shorter. |
|