Editorial for CTU Open Contest 2017 - Go Northwest!
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
- We need to count the number of ways to select two (not necessarily distinct!) points such that when we connect them by a line, the angle between the line and horizontal axis is
- How?
- The coordinates of points can help us to index diagonals to find out how many points lie on the same diagonal
- The northwest diagonals can be indexed by
- The northeast diagonals can be indexed by
- For each diagonal that contains points, the number of ways to select two points to form a line is
- That leaves us to sum the result over all diagonals and divide it by number of all options
- Total running time: or depending on the indexing of diagonals
Comments