Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Is sample correct? | Oleg Alexeev | 2199. Company Question | 20 Jan 2025 22:21 | 2 | Why for Q: 1 6 the answer is 5 6 and not 2 6 ? Having input "17 11 -1 -4 20 -24" for 5 6 we have 20 -24 = -4 and for 2 6 we have 11 -1 -4 +20 -24 = 2 why -4 is better than 2? Because we need to find 2 separate indexes i < j : |a[i] + a[j]| is minimal. Not sum of segment |a[i]+a[i+1]+...+a[j]|, but only 2 numbers a[i] and a[j]. | | Test 4 | Flamel | 2182. Broken Rum | 19 Jan 2025 17:15 | 1 | Test 4 Flamel 19 Jan 2025 17:15 Guys please help with test 4 Can't pass it Admin! Please give test 4 Edited by author 19.01.2025 18:48 | | easy bfs | ~'Yamca`~ | 2174. Dualism of Numbers | 18 Jan 2025 19:12 | 1 | | | New problems 2174-2199 | Sandro (USU) | | 17 Jan 2025 01:47 | 1 | Selected problems from Ural contests of the last few years were added to the Problem set. | | Any hints? | Zergatul | 2119. Tree Hull | 16 Jan 2025 00:08 | 4 | My thoughts for now: - Generate list of parents for every node, as well as weight sum (2nd parent, 4th parent, 8th parent and so on). This will allow to calculate weight sum between two nodes in O(log N) - Implement LCA (better with O(1) time?) - Store root of subtree in variable - When new node comes, find LCA(new node, subtree root). 2 variants here: 1) LCA = new node (need to add sum of weights from new subtree root to previous subtree root) 2) LCA = existing subtree root. What to do here? - When we remove node? Sort v_i by depth-first order. d[v_i] is the sum of weights from the root to v_i The answer, when there are n nodes, is: sum_{i=1}^{n} d[v_i] - d[LCA(v_i, v_{i+1})]; where v_{n+1}:=v_1 Implement these operations using std::set with a custom comparator that orders vertices using depth-first order. The proof of the formula is left to the reader as an exercise. WOW, that's really smart. Thank you | | If you have WA @ 14 | sailingoat | 1527. Bad Roads | 15 Jan 2025 10:01 | 1 | Note that there can be parallel edges, hence it is wrong to imply degree <= 100 | | No need for Johnson or Hungarian. | sleepntsheep | 1076. Trash | 14 Jan 2025 11:12 | 1 | SPFA with edmond karp is enough. AC 0.06 (test might be weak) | | Can somebody send me a good algo of min cost max matching? I've found only O(N^4) | vladu adrian | 1076. Trash | 14 Jan 2025 10:15 | 12 | Can somebody send me a good algo of min cost max matching? I've found a solution, but it runs in O(n^4), so I get time limit exceeded for some tests. > I've used a Hungarian algo that I've found on the NET. I don't know if it's correct because, for some tests it cycles to the infinite because no modifications can be done. Please, could somebody give me an algo that works? Here's my source. Usually it works fine but, as I said, in some cases it doesn't work. program trash; const nmax = 150; var a, d : array [1..nmax, 1..nmax] of integer; s : array [1..nmax] of integer; nz : array [1..nmax] of byte; m, b : array [1..nmax, 1..nmax] of boolean; hasm, found : boolean; mlin, mcol : array [1..nmax] of boolean; ming1 : integer; sum : longint; N, i, j : byte; procedure readdata; begin { assign(input, 'trash.in'); reset(input);} fillchar(s, sizeof(s), 0); readln(N); for i:=1 to N do begin for j:=1 to N do begin read(d[i,j]); inc(s[i], d[i,j]); end; for j:=1 to N do begin a[i,j]:=s[i]-d[i,j]; d[i,j]:=a[i,j]; end; readln; end; { close(input);} end; procedure DoZero; var i, j : byte; min : integer; begin for i:=1 to N do begin min:=a[i,1]; for j:=2 to N do if a[i,j]<min then min:=a[i,j]; for j:=1 to N do dec(a[i,j], min); end; for j:=1 to N do begin min:=a[1,j]; for i:=2 to N do if a[i,j]<min then min:=a[i,j]; for i:=1 to N do dec(a[i,j],min); end; end; function DoMark:boolean; var i, j, k, min, r : byte; begin fillchar(nz, sizeof(nz), 0); fillchar(m, sizeof(m), 0); fillchar(b, sizeof(b), 0); for i:=1 to N do for j:=1 to N do if a[i,j]=0 then inc(nz[i]); for k:=1 to N do begin {choose a row with min 0's} min:=255; for i:=1 to N do if (nz[i]>0)and(nz[i]<min) then begin min:=nz[i]; r:=i; end; if min=255 then begin DoMark:=false; exit; end; j:=1; nz[r]:=0; while (a[r,j]<>0)or(b[r,j]) do inc(j); m[r,j]:=true; {is marked} for i:=j+1 to N do if (a[r,i]=0) then b[r,i]:=true; for i:=1 to N do if (i<>r)and(a[i,j]=0) then begin b[i,j]:=true; dec(nz[i]); end; end; DoMark:=true; end; begin readdata; DoZero; while not DoMark do begin fillchar(mlin, sizeof(mlin), false); fillchar(mcol, sizeof(mcol), false); for i:=1 to N do begin hasm:=false; for j:=1 to N do if m[i,j] then begin hasm:=true; break; end; if not hasm then mlin[i]:=true; end; repeat found:=false; for i:=1 to N do if mlin[i] then for j:=1 to N do if (b[i,j])and(mcol[j]=false) then begin mcol[j]:=true; found:=true; end; if found then for j:=1 to N do if mcol[j] then for i:=1 to N do if (m[i,j])and(not mlin[i]) then begin mlin[i]:=true; found:=true; end; until not found; {i've made the marking} ming1:=maxint; for i:=1 to N do for j:=1 to N do if (mlin[i])and(not mcol[j])and(a[i,j]<ming1) then ming1:=a[i,j]; for i:=1 to N do for j:=1 to N do if (mlin[i])and(not mcol[j]) then dec(a[i,j], ming1); for i:=1 to N do for j:=1 to N do if (not mlin[i])and(mcol[j]) then inc(a[i,j], ming1); end; sum:=0; for i:=1 to N do for j:=1 to N do if m[i,j] then inc(sum, d[i,j]); writeln(sum); end. But how? Its complexity is O(n^4). I got TLE. Please, someone, tell me how to do it. no text Edited by author 12.12.2007 00:40 Usual mincost maxflow got easily AC here. I used maxflow with dijkstra to path searching. Dijkstra works O(n^2) ant increases flow by 1 eachtime. So we need only O(n) dijkstras to reach maxflow. Whole complexivity is O(n^3). In c++ is works for 0.171sec. How can you use Dijkstra since there are some edges which have minus values(values <0)? I used Bellman-Ford algo, and it doesn't run out of time. Use Dejkstra with potenciales. Modify weigth of eadges ... It's standart algorithm. I use SPFA but my problem got TLE with TEST#4 Testing machine is so fast now that an O(N^4) algo gets AC in less than 0.5s. Hungarian: 15ms Min cost flow with Dijkstra: 171 ms Min cost flow with optimized Bellman-Ford: 109 ms ¯\_(ツ)_/¯ What? How can min-cost flow with Dijkstra be used if negative edge exists (in residual graph)? Edit: Is it used with Johnson's potential. Edited by author 14.01.2025 10:15 | | TL#19 | sleepntsheep | 1569. Networking the “Iset” | 13 Jan 2025 22:25 | 2 | TL#19 sleepntsheep 13 Jan 2025 21:59 my O((M+N)^2) solution TL#19. Can I have hints on faster solution? | | RTE, Any Idea? | Tiojuan | 1016. Cube on the Walk | 13 Jan 2025 07:03 | 1 | | | AC! + hint on avoiding TLE. | sleepntsheep | 2055. Urban Geography | 12 Jan 2025 23:31 | 1 | good problem. dynacon! To avoid TLE: Use dynamic array instead of linked list for better locality. Break early when a first spanning tree is found. (important). Edited by author 12.01.2025 23:51 | | Passed or | foxlup | 1269. Obscene Words Filter | 12 Jan 2025 18:12 | 2 | 4 aceg ACEG {Ç}{Æ} {F}{E}{D} 3 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ {!}{"}{#}{$}{%}{&}{'}{(}{)}{*}{+}{,}{-}{.}{/}{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{:}{;}{<}{=}{>}{?}{@}{A}{B}{C}{D}{E}{F}{G}{H}{I}{J}{K}{L}{M}{N}{O}{P}{Q}{R}{S}{T}{U}{V}{W}{X}{Y}{Z}{[}{\}{]}{^}{_}{`}{a}{b}{c}{d}{e}{f}{g}{h}{i}{j}{k}{l}{m}{n}{o}{p}{q}{r}{s}{t}{u}{v}{w}{x}{y}{z}{{}{|}{}}{~}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{ }{¡}{¢}{£}{¤}{¥}{¦}{§}{¨}{©}{ª}{«}{¬}{}{®}{¯}{°}{±}{²}{³}{´}{µ}{¶}{·}{¸}{¹}{º}{»}{¼}{½}{¾}{¿}{À}{Á}{Â}{Ã}{Ä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 sleepntsheep 9 Jan 2025 22:19 turns out my function for checking if point lies on segment was wrong. | | Give me some hints, ples | Михаил | 2145. Olympiad for Everyone | 8 Jan 2025 22:35 | 4 | as common we must use some original in this: if first k best student can solve hardest problem they are absolutely equivalent for assignment to first problem Consider difficulties in descending order | | To admins: wrong Clang? | Dmi3Molodov | 1052. Rabbit Hunt | 8 Jan 2025 14:37 | 1 | | | Is it possible to solve it problem in Python? | kisvadim | 2014. Zhenya moves from parents | 8 Jan 2025 14:13 | 2 | I have 'Time limit exceeded' after 13 test. Возможно ли решить данную задачу на Питоне? У меня после 13 теста лимит времени исчерпан. Yes, user named ixiolirion did so (barely withing time limit, but still). | | If you have problems with Test #17 | Semm | 1427. SMS | 5 Jan 2025 21:08 | 1 | Advertisement contains up to 100000 symbols and ends with a newline. So may need to store 100000 symbols + newline symbol + one '\0' symbol. I had problems with this using fgets in C++. | | Fast? | sleepntsheep | 1097. Square Country 2 | 5 Jan 2025 14:25 | 2 | Fast? sleepntsheep 3 Jan 2025 18:13 Can it be faster than O(M^2)? Why do you care about this? The statment says "1 ≤ M ≤ 100",I think it means "Ok,the speed of the correct way is O(M^2)". | | Can word w_i be duplicated | sleepntsheep | 1542. Autocompletion | 3 Jan 2025 11:11 | 3 | Okay, turn out the answer is NO | | Admin: Why actually needed that problem, if it cant solveable without calculate all possible values in advance? | coder | 2061. OEIS A216264 | 3 Jan 2025 06:20 | 2 | There are for n=1..60 all values already exist in internet. Only required calculate for n=61. But it takes more 20 hours. so do you recommend solving on timus or not? |
|
|