No.239 Nyanpass
タグ : / 解いたユーザー数 609
作問者 :
Problem Statement
It is said that Renge Miyauchi (commonly known as Renchon) greets people with "nyanpass" at any time and on any occasion.
By extension, a person who greets with "nyanpass" at any time and on any occasion is called "Renchon-like".
There are $N$ villagers in the village, assigned villager numbers \(1 ~ N\).
The greeting history of the $N$ people is given as an $N \times N$ matrix $A$. $A_{ij}$ represents what villager $j$ said when villagers $i$ and $j$ greeted each other.
When exactly one person among the $N$ people is Renchon-like, we say that Renchon has been "identified".
If Renchon can be identified, output that villager number; otherwise, output -1.
Input
$N$
$A_{11}$ $A_{12}$ $\ldots$ $A_{1N}$
$A_{21}$ $A_{22}$ $\ldots$ $A_{2N}$
$\ldots$
$A_{N1}$ $A_{N2}$ $\ldots$ $A_{NN}$
- $2 \leq N \leq 100$
- $A_{ii}$ is "-" (excluding the quotation marks)
- $A_{ij}$ is a string of between 1 and 30 lowercase English letters.
Output
If Renchon can be identified, output that villager number; otherwise, output -1.
Sample
Sample 1
Input
4 - nyanpass uissu ohayo konbanwa - ohayo ohayo ohayogozaimasu nyanpass - komachanyuuna konnichiwa nyanpass komachanohayo -
Output
2
Sample 2
Input
3 - nyanpass ohayo nyanpass - chicchakunaiyo nyanpass nyanpass -
Output
-1
Villagers 1 and 2 are Renchon-like, so the answer is -1.
Sample 3
Input
3 - ohayo nyanpass nyanpass - ohayo nyanpass ohayo -
Output
1
People other than Renchon might say "nyanpass" now and then, too.
Sample 4
Input
2 - ohayo zukoo -
Output
-1
No Renchon here...
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。