This page is still under construction.

Parts of this page are still being built. What you see may change.

Ships

Time limit1sMemory limit128 MB

Summary
Given partial knowledge of seven non-overlapping tetromino ships on a grid, decide if all 28 ship squares can be uncovered with at most one miss against every consistent arrangement.
Level

Hard8 of 10

Topics
Backtracking, Brute force, Implementation
Solved
No attempts yet

Problem

Two players hide ships on a grid and take turns guessing where the other player's ships are. In this version your opponent has placed exactly seven ships on a rectangular grid, one ship for each of the shapes below.

xx  xx    xx  x      x   x
xx   xx  xx   xxx  xxx  xxx  xxxx

Every shape covers four squares, so the seven ships together cover 28 squares. A ship may be rotated, but it may not be mirrored. Every ship lies completely inside the rectangle and no two ships overlap, although a ship may touch another ship or the border.

The game is already under way and some squares have been uncovered. You are given a grid describing what you know right now. Each square holds one of three characters:

  • x if a ship covers the square
  • o if no ship covers the square
  • . if you have not uncovered the square yet

From here you uncover . squares one at a time, and you may pick the next square after seeing the result of the previous one. Uncovering a ship square is a hit, uncovering an empty square is a miss. Decide whether you can uncover all 28 ship squares while taking at most one miss, against every arrangement that agrees with what you already know. An order that works only when you guess luckily does not count.

If your current knowledge already pins down the 28 ship squares, no miss is needed. Otherwise you may spend the single miss, and once you know its result the ship squares must be pinned down, whichever arrangement turns out to be the real one.

Every grid in the input agrees with at least one arrangement.

Input

The input holds several game situations. Each one starts with a line containing two integers ww and hh, the width and the height of the grid, with 2≤w,h≤162 \le w, h \le 16.

Each of the next hh lines holds a string of ww characters, each of them x, o or ..

Blank lines may appear between games. The input ends with a game where w=0w = 0 and h=0h = 0, and that game is not processed.

Output

For each game print the line Game #k, where kk is the position of the game in the input counting from 1, then a line holding yes. if you can uncover all ship squares while taking at most one miss, or no. otherwise.

Print one empty line between consecutive games. Do not print an empty line after the last game.

Examples2

  1. Example 1

    Input
    10 10
    .x..x.....
    oooooxoooo
    oxooxxx...
    xxoooooo..
    xoooxooo..
    ooxxxxoo..
    oooooxxoox
    ooooooxoox
    ooooooooxx
    oooooooooo
    
    
    0 0
    
    Expected output
    Game #1
    yes.
    
  2. Example 2

    Input
    10 10
    oxxxxooooo
    oooooxoooo
    oxooxxxoxx
    xxooooooxx
    xoooxooooo
    ooxxxxoooo
    oooooxxoox
    ooooooxoox
    ooooooooxx
    oooooooooo
    
    10 10
    oxxxxooooo
    oooooxoooo
    oxooxxxo..
    xxoooooo..
    xoooxooooo
    ooxxxxoooo
    oooooxxoox
    ooooooxoox
    ..o..oooxx
    ..o..ooooo
    0 0
    
    Expected output
    Game #1
    yes.
    
    Game #2
    no.