Mock CCC '22 1 S5 - Berkeley Math Tournament Awards Ceremony

View as PDF

Submit solution


Points: 35 (partial)
Time limit: 0.25s
Memory limit: 1G

Problem type

Kaity is the tournament director for the Berkeley Math Tournament, a tournament so large that Kaity runs it on an infinite 2D plane.

The 2D plane is templatized by an N×M rectangle R, the top-left corner being (0,0) and the bottom-right corner being (N1,M1). Square (x,y) has an obstacle if and only if square (r,s) in the template rectangle has an obstacle, where r and s are respectively remainders when x and y are divided by N and M. One can only travel directly between two squares if their Manhattan distance is 1 and both are empty.

Kaity is running the awards ceremony at (0,0). She wishes to know for Q distinct empty points (xi,yi) whether someone at (xi,yi) can travel to (0,0) without running into any obstacles.

Constraints

1N,M100

1Q2105

|xi|,|yi|109

In tests worth 1 mark, Q103.

Input Specification

The first line contains two integers, N and M.

The next N lines contain a string of M characters, each character being either . if it is empty or # if it contains an obstacle.

The next line contains one integer, Q.

The next Q lines contain two integers, xi and yi, indicating a query point (xi,yi).

The input is set such that each of these points and (0,0) will not contain an obstacle.

Output Specification

Output Q lines. On the ith line, output yes if (0,0) is reachable. Otherwise, output no.

Sample Input 1

Copy
6 9
..#####..
..#...#..
......#..
..#####..
..#......
..#...#..
5
1 4
5 4
1 -5
5 -5
-1000000000 0

Sample Output 1

Copy
yes
no
no
yes
yes

Comments


  • -3
    ColonelBy_team10  commented on Dec. 31, 2021, 3:51 p.m.

    X Y is misleading, as it connotes an reference to Cartesian Coordinates. X, Y is actually Row, Then Column, which is Y, X in the cartesian system.


  • 0
    ColonelBy_team10  commented on Dec. 30, 2021, 3:31 p.m.

    If x is negative, then r is negative. Which item in the template grid would a negative r be referring to?


    • 1
      xiaowuc1  commented on Jan. 1, 2022, 1:56 a.m.

      This problem is using the convention that the remainder must be nonnegative and less than the divisor. This is a widely accepted convention which comes into conflict with certain programming language standards - however, contextually it should be clear that this is the definition being used.