Battleship P19727


Statement
 

pdf   zip

0.67 Ann and Bob like to play a variant of Battleship. First, they agree on the number of rows rr and the number of columns cc of a rectangular grid, and also on a length mm. Afterwards, Ann decides a place to hide exactly one ship of size 1×m1 \times m completely inside the grid, either horizontally or vertically. Then, Bob tries to sink Ann’s ship by shoting at nn cells of the grid. For every shot, Ann must say if the ship has been hit, or if the shot has been a miss.

0.33

You are looking at one game between Ann and Bob, and you suspect that Ann is cheating. To confirm or refute your suspicions, please count the number of positions where the ship could be placed according to Ann’s answers.

Input

Every case begins with rr, cc, mm and nn. Follow nn triples i,j,xi, j, x, where 1ir1 \le i \le r is the row of the shot, 1jc1 \le j \le c is the column of the shot, and xx is a character that is ‘h’ or ‘m’ depending on whether the shot is a hit or a miss according to Ann. Assume 1r1081 \le r \le 10^8, 1c1081 \le c \le 10^8, 2m1002 \le m \le 100, and 0n1050 \le n \le 10^5. The coordinates of all the shots are different.

Output

For every case, print the number of possible locations of the ship hidden by Ann. If this number is 0 or if Ann’s answers are clearly wrong, print “Ann is cheating.”.

Public test cases
  • Input

    1 2 2 0
    4 6 3 0
    4 6 3 1  2 3 m
    4 6 3 1  2 3 h
    4 6 3 2  2 3 h  2 4 m
    4 6 5 0
    3 3 4 0
    1 7 4 1  1 4 m
    1 7 4 2  1 4 h  1 1 h
    1 7 4 2  1 5 h  1 1 h
    100000000 100000000 2 0
    

    Output

    1
    28
    23
    5
    3
    8
    Ann is cheating.
    Ann is cheating.
    1
    Ann is cheating.
    19999999800000000
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++