3-Dimensional Connect 4

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types

Raymond is very good at Connect 4. He thinks that regular Connect 4 is boring, so he plays a 3D version instead. The 3D version consists of 6 parallel 6\times6 Connect 4 boards. Two players use red and yellow chips to attempt to connect 4 of their same color horizontally or vertically, across any of the three dimensions. Diagonal lines will not be counted for simplicity. Raymond is too lazy to check the board after a game himself, so he will pay you in points to check for him. Raymond always plays red.

Input Specification

The input will consist of 6 line-separated 6\times6 grids, each denoting the chips in one slice of the 3D gameboard, and containing 36 characters that consist of R (for a red chip) and Y (for a yellow chip).

Output Specification

Output the number of distinct occurrences where 4 red chips are in a horizontal or vertical line in any of the three dimensions. If there are no such occurrences, output lost (Raymond is very competitive).

Note: Do not prompt for input, as this will cause the judge to take the prompt as the solution.

Sample Input

RYRRRY
RRYYRY
YYRYYR
YRYYRR
YYRRYR
RRYYRY

RYRRRY
RRYYRY
YYRYYR
YRYYRR
YYRRYR
RRYYRY

RYRRRY
RRYYRY
YYRYYR
YRYYRR
YYRRYR
RRYYRY

YRYYYR
YYRRYR
RRYRRY
RYRRYY
RRYYRR
YYRRYY

YRYYYR
YYRRYR
RRYRRY
RYRRYY
RRYYRR
YYRRRY

YRYYYR
YYRRYR
RRYRRY
RYRRYY
RRYYRR
YYRRRY

Sample Output

3

Comments


  • 0
    d3m0nc0d3r95  commented on Sept. 19, 2019, 1:54 p.m.

    I believe my solution is correct. I've rechecked the algorithm multiple times and also tested it with the sample case given. I designed a more general algorithm for solving this problem for an nxnxn cube with determining k connected red chips. I've also tested the algorithm on smaller cube sizes like 3x3x3 and it works fine. Kindly let me know if I'm understanding the problem incorrectly, otherwise, I believe my solution is correct.


    • 3
      wleung_bvg  commented on Sept. 19, 2019, 4:47 p.m.

      You fail a few fairly trivial cases, though it can be easily fixed. Remember that c-style strings require an extra byte of memory for the null character. Failure to allocate this extra byte can result in undefined behaviour and data written to memory addresses where you would least expect, and cause your solution to fail in places you never thought was possible.


  • -2
    christinakemp  commented on May 15, 2019, 4:35 p.m.

    Can the 4 in a row overlap? Ie. If you have 6 in a row does that count as 3?


    • -16
      magicalsoup  commented on May 15, 2019, 6:41 p.m.

      This comment is hidden due to too much negative feedback. Click here to view it.