CF329A.Purification

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n×nn×n grid. The rows are numbered 11 through nn from top to bottom, and the columns are numbered 11 through nn from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:

The cleaning of all evil will awaken the door!Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.

The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.

You would like to purify all n×nn×n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.

Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

输入格式

The first line will contain a single integer nn ( 1<=n<=1001<=n<=100 ). Then, nn lines follows, each contains nn characters. The jj -th character in the ii -th row represents the cell located at row ii and column jj . It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

输出格式

If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts xx "Purification" spells (where xx is the minimum possible number of spells), output xx lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

输入输出样例

  • 输入#1

    3
    .E.
    E.E
    .E.
    

    输出#1

    1 1
    2 2
    3 3
    
  • 输入#2

    3
    EEE
    E..
    E.E
    

    输出#2

    -1
    
  • 输入#3

    5
    EE.EE
    E.EE.
    E...E
    .EE.E
    EE.EE
    

    输出#3

    3 3
    1 3
    2 2
    4 4
    5 3

说明/提示

The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.

In the second example, it is impossible to purify the cell located at row 11 and column 11 .

For the third example:

首页