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

Hint.
Posted by jk_qq 17 Oct 2017 13:42
Find domino with the least number of all 2*n numbers (second number have to be the biggest possible among all dominos with least first number). Let's denote minimal number as MIN and maximum as MAX.
Put it in the first position with left half to be the minimal number.
Then find all dominos with number more than MAX. Easy to see we already know it's orientation because of first domino (think a moment here). Put all dominos like that (use std::set<pair> or similar ds).
Repeat process.

Mine impl uses one set for finding first domino and one for finding all dominos with number more than current MAX. (O(N log N))