Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Good problem! | wangbicheng1 | 1162. Currency Exchange | 28 Jul 2026 12:07 | 2 | You need to have a deep understanding of the bellman-ford algorithm, especially THE RELAXING OPERATION 10'000 iterations - WA21 100'000 iterations - WA21 1'000'000 iterations - AC (but 0.5sec) | | Some review | Igor Parfenov | 1464. Light | 28 Jul 2026 11:13 | 2 | The idea of problem is pretty interesting. But for me it was implementation hell. Made it with almost 1st submit, so I'll describe my way of avoiding "implementation hell". First of all obvious things: x[i] -= x0, y[i] -= y0, so origin is at zero. x[n]=x[0], y[n]=y[0] to reduce amount of 'if's. Second, all that we love with precision maths. I.e. a == b --- fabs(a-b)<eps a > b --- a > b + eps a >= b --- a > b - eps eps=1e-8 is enough here, but I did it without trigonometry The main idea is that every segment covers some range of angles [a1;a2], so we have a set of "control points" of the form "angle;seg-i-start", "angle;set-i-end". So when you have this set of control points, segments will not change their relative order between two consecutive control points which can be checked by intersecting a ray and checking square of distance. Now on how to avoid trigonometry in these and other problems like convex hull - just store vectors (segment endpoints). When comparing them for an "angle", first check the side. Let side=0 be the [0;pi) range - that is 'dy>0 || dy==0 && dx>0', then side=1 goes for [pi;2pi) range. Then you just compare sides, and if side is the same, check the sign of cross product for comparison. You will also need a special record for 2pi (side=2), I coded it as dx=0,dy=0, but be careful to treat it as (1,0) when raycasting later. Now, ignore segments which contain origin in negative subplane (or on zero, i.e. no control points for them). Then the only thing to be dealt with is crossing 2pi-0 boundary. Criteria here is 'y[i]<0 && y[i+1]==0' - then it starts at (x[i];y[i]) and ends at (0;0). Or 'y[i]<0 && y[i+1]>0' then it starts at (x[i];y[i]), ends at (0;0), then starts at (1;0) and ends at (x[i+1];y[i+1]). These are just for 'angular' sorting of control points. After that you will have first control point at (1;0) (angle=0) and last control point at (0;0) (angle=2pi). The rest is just running through them. Pick all control points which are 'equal' on that angular criteria, and process them - i.e. add/del corresponding segments to the heap according to px[i];py[i] ray intersection length for that control point. Let the next control point which is 'greater' according to angular criteria be 'j', after that pick topmost (nearest) segment from the heap, get intersection with px[i];py[i] ray, and px[j];py[j] ray (here don't forget to treat 0;0 as 1;0). After that add their cross product to the answer. | | How to solve it? | Fdg | 1772. Ski-Trails for Robots | 27 Jul 2026 19:14 | 6 | DP + sqrt-decomposition (or tree-like structure) I think that Djkstra in graph of robot's ends will work. No need for Dijkstra or sqrt decomposition :) Nodes are (0,s), (i,l[i]-1), (i,r[i]+1) where applicable. The main idea is that you do not have to bend towards edges if you can go in a straight line, you can always make that adjustment later when necessary at the same cost. However, tracing all these rays for every obstacle will quickly MLE/TLE. To work around this you need to answer quickly location of nearest obstacle further ahead. This can be done with going back-to-front and paint over segment tree with lazy propagation. Nodes which have no obstacles ahead going in a straight line are terminal nodes (start may also be such, then the answer is 0). So it's K*log(N) to track those nearest obstacles for each of K*2+1 nodes, and then easy BFS from left to right. And don't forget about int64. Edited by author 08.07.2026 23:27 (LLM-written, always verify, but current AC #1 beating all previous entries) There’s another O(k log n) way: treat the current answer as a function of the trail number. After each obstacle this function is still made only of `+1/-1` linear pieces, and processing an obstacle just replaces its blocked interval by at most two new pieces. A lazy segtree is enough. (LLM-written, improved to 0.015s) There’s also an amortized O(n + k) way: store only the boundaries of those `+1/-1` linear pieces. Each obstacle creates only constantly many new boundaries and may erase old ones; since every erased boundary had to be created earlier, the total number of such operations is linear. The bounded trail indices allow predecessor/successor queries in O(1). | | WA/RE18 | Solver | 1464. Light | 27 Jul 2026 12:19 | 1 | There is a segment whose extension contains the origin | | a few tests | esbybb | 2070. Interesting Numbers | 26 Jul 2026 19:56 | 2 | 1000 100000000000 99999971585 10 100 86 17 500 476 13841287201 = 7^12 25937424601 = 11^10 31381059609 = 3^22 68719476736 = 2^36 152587890625 = 5^16 | | hint? | coder | 2057. Non-palidromic cutting | 25 Jul 2026 15:15 | 1 | hint? coder 25 Jul 2026 15:15 minimum is always -1, 1, or 2 ? 1) S = aaaa...aa => -1 (S = [a]*n) 2) S = aaabaaa on center different symbol ==> -1 (S = [a]*m + 'b' +[a]*m) 3) S = ababababa...ababa ==> -1 (S = [ab]*m + 'a' there S is palindrome) 4) S - is not palindrome, ==> 1 5) S - is palindrome, there at least two different symbols => 2 Proof 5: let a = S[1], b = S[i] , and all S[1] = S[2] = ..=S[i-1] = a, There S is palindrome. S = aaaabxy....baaaa Take T1 = aaab T2 = xy...baaaa T1 - is not palindrome 5.1) T2 also is not palindrome, minimum cut is 2. 5.2) T2 also palindrome 5.2.1) i > 2, there two or more 'a' in T1. T1 = aaabx T2 = y....baaaa There T1 and T2 both are not palndrome, (think about it). 5.2.2. i = 2. T1 = ab But T2 palindrome, so S = abababababa...aba, this can't be allowed, because S != [ab]*m + 'a' already checked.
| | help with 52 pls | 🎧 Vadim Barinov \Frez_Fstilus/'` | 1509. Domino Recognition | 24 Jul 2026 22:20 | 3 | What may cause this judgement result? I think there is an error in your domino size cheking function or something similar. See your other topic for details. Thanks a lot. I really returned to this problem 9 years later and mistake was staring me in the eye. I didn't check min distance for 0-2 and max distance for 1-1. | | I don't understand what I'm doing wrong anymore. | lain | 1001. Reverse Root | 24 Jul 2026 12:38 | 1 | import sys, math numbers = [] empty_lines = 0 for line in sys.stdin: line = line.strip() if line == "": empty_lines += 1 if empty_lines == 2: break else: empty_lines = 0 numbers.extend(line.split()) for num in reversed(numbers): print(f"{math.sqrt(int(num)):.4f}") | | The real solution | Huang Da | 1789. Searching for the Dodecahedron | 24 Jul 2026 12:03 | 2 | Don't know why so many authors have posted 2*n-1.. That's obviously a wrong solution... Just think about if the stone is in the odd and the man touches the odd, things will be done smoothly. The real solution is writing a "checker" for this problem, and then BFS over possible states from 2^n-1 to reach 0 (on bitmask of where it can be located). That produces a nice pattern which is always 2*(n-2), and ofc. shortest possible since it's fair BFS. 2 3 ... n-2 n-1 2 3 .... n-2 n-1 for odd N 2 3 ... n-2 n-1 n-1 n-2 ... 3 2 for even N | | WA7 | Solver | 1789. Searching for the Dodecahedron | 24 Jul 2026 11:59 | 1 | WA7 Solver 24 Jul 2026 11:59 | | I have AC with such idea but I don't understand how to get a formula or faster solution | IlushaMax | 1023. Buttons | 24 Jul 2026 10:48 | 4 | var i,n,l,j:longword; found:boolean; begin readln(n); repeat found:=False; for j:=3 to n div 2 do begin if n mod j=0 then begin found:=True; break; end; end; if found then n:=j; until not found; writeln(n-1); readln; end. Please help me to optimize my code. It's 0.405 sec for j := 3 to sqrt(n) do will help you :) > for j := 3 to sqrt(n) do will help you :) will it? for sqrt(8) = 2.8, but answer should be 4 - 1 = 3 Two eparate loops for n%prime (prime>2) and n/2%prime if n%2==0 | | What is your idea of solution? | Vedernikoff Sergey (HSE: EconomicsForever!) | 1658. Sum of Digits | 23 Jul 2026 11:12 | 4 | Mine quite straightforward realization works about 1 sec. and uses almost 60 megabytes of memory. Please, give an idea how to solve it more quickly... Edited by author 17.03.2010 14:10 Struggled with WA2/WA4 for a lot of submits. Tricks are tracking min-length and even then getting least possible value can be tricky. My solution is DP(900*8100)*9 to get minimal length. Then greedy BACKtracking from higher to lower using least possible digit (so you get as many '1' as possible, then as many '2' and so on) over edges that follow minimal length path. As for memory - two arrays of uint8_t. That's 14Mb. You can also sacrifice backtracking array, and perform it on the fly during generating output, would be bigger runtime, but half the memory. | | at last i solved it | Rustam | 1658. Sum of Digits | 23 Jul 2026 10:23 | 2 | i have +27 submites on it just because i forgot tests like that: 1 808 6464("No solution") Edited by author 10.10.2009 04:16 | | Для тех, кто не понял | Daulet | 1740. Deer is Better! | 21 Jul 2026 11:57 | 5 | Скорость оленей не ограничена, т.е. они могут хоть телепортироваться считай Здесь факт лишь в том, что они должны пробежать за H часов K километров По этому минимальное например при данных 30 11 2 будет равно 4 Объясняю: За 4 часа олени пробегут 22 км (ну, 11*2 просто) , и так как осталось 8 км, то они могут это расстояние просто перелететь (телепортнуться), ведь это меньше 11 км, поэтому им и время не нужно (они же не прошли 11, значит и 2 часа не нужно). А с максимальным все очень просто, это просто время если бы олени двигались с постоянной скоростью, но могли немного перебежать нужное расстояние(главное чтобы оно было не больше к) При 30 11 2 макс время будет 6 часов, тк только тогда олени достигнут своих 30км изначальных (ну немного больше пробегут - 33 км) Надеюсь кому-то поможет в решение The problem is just from Russia. Pay attention, the Chukchi is running, not an Eskimo, not an Indian, but a Chukchi. And in Russia everything is relative. And the position of the Chukchi is relative. That is, the Chukchi is located somewhere in the Yamal-Nenets district. On the territory within a radius of 100 kilometers from the telephone tower. In 2 hours he will be in an area within a radius of 100 kilometers from another telephone tower. That is, he will reach Moscow in 4 hours, plus or minus 2 hours. Something like this. Translation problems. Что-то ваши объяснения не очень логичны. Вы уверены, что именно эта логика заложена авторами задачи ? | | Any Help/Hint | Amil Khare | 1142. Relations | 21 Jul 2026 11:40 | 6 | Hello, I am not that strong in DP but I have been trying hard to understand the problem. I tried coming up with a solution however got WA. I cannot completely understand the hints given before, PLEASE HELP !!! There are two dp-approaches already described on the webboard So I have accepted with dp I have two dp Stirling numbers of the second kind and factorial Then precalculate answer array I have seen the 2 DP solutions however I still don't understand how do they arrive at the relation? Can you describe in detail if possible, Please ! There are X groups consisting of equal numbers. X=1,2,..n. What does it mean, to put some '<' and '>' signs between them? It is just to define some order relation. Just assign one group as the greatest, another group as the second greatest etc. So we find number of ways to make groups and multiply it by number of ways to make ordering https://ideone.com/00UUdf Edited by author 23.07.2026 09:22 | | Strange printf behavior | it4.kp | 1461. Christmas Garland | 21 Jul 2026 11:28 | 12 | Strange but when i use printf("%s",s.c_str()); I get WA on test 11, but if change it to cout<<s; it's become AC. Can somebody tell me why? Well, I got WA 3 during the contest but I'm pretty sure my idea is right, ahy tests ? I first, have WA3 too. That was because I misunderstood the problem statement... I thought that there cannot be two consecutive segments with y=0 which is wrong. Please help me. I still get WA on test 3 I'm a loser :( Edited by author 31.07.2007 15:38 I don't know why you have WA, but even if you fix all your bugs you definetly get TLE, since next_permutation works in exponential time and the length of string could be 100000! Give me some tests please I've WA #3 P.S. And what about tests with N = 1? Here are some tests Test 1: 4 uudd Answer 1: No solution Test 2: 4 uhhd Answer 2: uudd Test 3: 8 udududud Answer 3: ududuhhd Test 4: 32 uuuuuuuuuudddddduuuuuudddddddddd Answer 4: uuuuuuuuuudddddhdddddududududuhd Test 5: 41 uuuuuuduuuuuddddddduuuuuuuuuhdddddddddddd Answer 5: uuuuuuduuuuuddddddhddddududududududududud Test 6: 15 uuuuuuuhddddddd Answer 6: No solution p.s.: there is no tests with n=1. EDIT: Test 5 is correct now Edited by author 13.08.2006 22:01 Thanks for the tests, it turned out that I have misread the problem :(, anyway, thanks for your help Just feed output as input till it's "No solution" and see results. It might help finding bugs. Thanks for the tests! 4th helped with WA3 to get AC. I considered that 'h' is not allowed at y=0 in if-you-can-finish-itr (that is n==1 && y==0 -> false), but forgot to check for y=0 on 'h' in incrementer/finisher loops. | | WA 17 test | anotherworld | 2214. Quality Emitter | 20 Jul 2026 15:27 | 1 | 4 3 2 3 9 3 7 9 5 3 8 3 8 2 0 5 answer : 62 | | AC with Pollard's rho algorithm | Keworker `~ | 2102. Michael and Cryptography | 20 Jul 2026 12:02 | 4 | I pass this problem with Sieve of Eratosthenes, but i think solution with Pollard's rho algorithm is funnier, and wrote it too. If you cant pass it with this algo just use all prime modules from 1'000'000'007 to 1'000'001'393. Did you check small dividers? ro pollard works very poorly with them If TL let me check all with O(sqrt(n)), I do it. I invoke rho pollard only if can not pass test with O(sqrt(n)) Sieve up to 1e6 - WA54 Sieve up to 1.5e6 - WA59 Sieve up to 1e7 - AC :) | | What's your algo? | ACSpeed | 1604. Country of Fools | 20 Jul 2026 11:31 | 6 | Can you guys share your approach ( and proof if possible ) because mine, though AC, is not very certain. I rely on greedy approach which output pairs with maximum number and minimum number. Use sort and find min and max after output each pair. Quite slow, 0.14s :) Greedy approach is fine but why output pairs with maximum number and minimum number ?? Can you guys share your approach ( and proof if possible ) because mine, though AC, is not very certain. I rely on greedy approach which output pairs with maximum number and minimum number. Use sort and find min and max after output each pair. Quite slow, 0.14s :) I used a max heap in which I hold pairs like, number i (index of the sign) and frequency of that sign. Each time I pop out from that heap the 2 index with maximal frequency, decrement their frequency and update the heap from their indexes. I was sure that there is a more simplier aproach to that problem(like greedy), without using heap, but I was just 99.9% sure that with heap I will got AC, and so it was. :) The same here. I'm using heap, but I'm pulling entries one by one, decrementing and not adding them back until next entry is pulled. I was 146% sure this would work when I decided to implement this algo and it not that bad in terms of time: O(n log k). But I wondered if there is a simple straightforward algo that also would work. Turned out there is. I created an array of pairs (quantity, index) and sorted it. Output the maximum and the next one with a positive quantity, and if there are elements with the same quantity that remains at the maximum, I output them the same way, each step decreasing the number of the output element Sorry for my English tests with my answers: 4 8 5 4 3 1 2 1 2 1 2 1 2 1 2 3 1 3 4 1 3 4 1 3 4 5 9 7 4 4 3 1 2 1 2 1 2 1 2 1 2 1 2 4 3 1 2 4 3 5 1 4 3 5 1 4 3 5 Pick maximum according to remaining amount which is not equal to previous sign, heap is enough for that (though I got 0.125 AC with O(N^2) when tested this approach). Heap gave 0.015 Edited by author 20.07.2026 11:41 | | WA #11 | Solver | 2074. Timus problems classifier | 18 Jul 2026 11:26 | 1 | WA #11 Solver 18 Jul 2026 11:26 When I sorted all problem according to their set of topics for merging at output I forgot to make it stable, so that the order of grouped problems stays increasing. |
|
|