ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1743. Domino Sorting

Algo
Posted by Zayakin Andrey[PermSU] 24 Jan 2010 00:35
What is your comlexiety of your algo?
my O(n^2) solve this.
Re: Algo
Posted by Lezhankin Petr [Ufa] 25 Jan 2010 20:13
Do u claim that u've got AC with solution in O(n^2)? (n is up to 100000)
Re: Algo
Posted by Zayakin Andrey[PermSU] 26 Jan 2010 16:14
Build all 2*n pairs of numbers, sort this(firstly by first numbers by non-decreasing order, if first number is equal - sorted by second numbers by non-increasing order). And using greedy build sequence with length equal N start with a[0], if we don`t find solution, start with a[1] and so on, if we have solution we stop algo.
Sory for my english.
Re: Algo
Posted by ilucian1 2 Feb 2010 15:33
his algorithm is very good but I think its complexity actually is n*log(n) (sorting) + n (finding the solution)
Re: Algo
Posted by svr 3 Feb 2010 11:04
I suggest math righ algo;
Let a:[1..n]->{0,1} - rotate or not.
(i,j)- red if must a[i]!=a[j]
(i,j)- blue if must a[i]=a[j]
Blue connections- equality relation and we form m classes
If inside some class there is a red edge- "NO"
BFS in superGraph of classes
If find not even cicle "NO"- edge along level of graph
Rotate classes on even levels.
12 tests Ok test13 TL

Edited by author 03.02.2010 16:59

Edited by author 03.02.2010 16:59
Re: Algo
Posted by Vladislav 21 Sep 2011 20:39
The complexity can be O( n*log(n) ). Sort the 2n pairs as described(increasing by first, decreasing by second) and start from a[0]. The greedy alg. is as follows: go throught a1,a2... , when we find something which we can include and haven't included, include it. It is correct, because for a0 we can only put it in the begining or (inversed) at the end. But if we put it in the end, we can invert the whole sequence and get a solution with it at the begining and so on. So a0 will always give a solution (if possible) and we need one pass.