Dart
Time limit2sMemory limit1024 MB
Given a convex polygon dartboard and two lists of dart throws, compute each player's total score modulo 1e9+7 and report the winner.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Prefix sum
- Solved
- No attempts yet
Problem
Yeongmin and Hyeonbin always have dinner together, and they always disagree about the menu. So they agreed to settle it fairly with darts: the winner picks the menu. Neither of them knows darts well, but both like programming, so they defined the following scoring rules.
- The dartboard is a convex -gon. No three of its vertices are collinear.
- If a dart lands strictly inside the dartboard, the score is twice the area of the dartboard.
- If a dart lands on the boundary of the dartboard, the score is 0.
- If a dart does not land inside the dartboard, the score is computed as follows.
- From the point where the dart landed, draw two tangent lines to the dartboard. If a tangent line touches the dartboard at a vertex, the tangent point closer to the dart is used.
- Draw the segment connecting the two tangent points.
- The segment divides the dartboard into two regions. The score is twice the area of the smaller of the two regions (the one that is not larger).
Yeongmin and Hyeonbin each throw the dart times. The total score of each person is taken modulo , and the person with the larger remainder wins.
Input
The first line contains the number of vertices and the number of throws . (, )
From the second line through line , each line contains the x and y coordinates of a vertex of the dartboard, separated by a space. The vertices are given in counterclockwise order.
From line through line , each line contains the x and y coordinates of the point where one of Yeongmin's darts landed, separated by a space.
The next lines contain the x and y coordinates of the points where Hyeonbin's darts landed, separated by a space.
All coordinates are integers with absolute value at most .
Output
On the first line, print "ym" if Yeongmin wins, "hb" if Hyeonbin wins, or "same" if the two scores are equal.
On the second line, print Yeongmin's score and Hyeonbin's score, each taken modulo , separated by a space.