N×N個ã®ãƒžã‚¹ã‹ã‚‰æˆã‚‹ã‚°ãƒªãƒƒãƒ‰ãŒã‚る。最åˆã™ã¹ã¦ã®ãƒžã‚¹ã¯ç™½è‰²ã§ã‚る。以下ã®æ‰‹é †ã«å¾“ã£ã¦é»’色ã®ãƒžã‚¹ã‚’増やã—ã¦ã„ã。
上ã‹ã‚‰å¶æ•°ç•ªç›®ã‹ã¤ã€å·¦ã‹ã‚‰å¶æ•°ç•ªç›®ã§ã‚るマスã®ä¸ã§ã€ç™½è‰²ã®ãƒžã‚¹ã‚’1ã¤é¸ã¶ã€‚é¸ã‚“ã マスã¯é»’色ã«å¤‰åŒ–ã™ã‚‹ã€‚ã•ã‚‰ã«ã€ãã®ãƒžã‚¹ã®ä¸Šä¸‹å·¦å³ãã‚Œãžã‚Œã®æ–¹å‘ã«ã¤ã„ã¦ã€éš£æŽ¥ã—ã¦ã„る白色ã®ãƒžã‚¹ã‚‚連鎖的ã«é»’色ã«å¤‰åŒ–ã™ã‚‹ã€‚ã“ã®é€£éŽ–ã¯ãã®æ–¹å‘ã«ç™½è‰²ã®ãƒžã‚¹ãŒå˜åœ¨ã—ãªããªã‚‹ã¾ã§ç¶šã。(以下ã«ä¾‹ã‚’示ã™)
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡â–¡
↓上ã‹ã‚‰4番目ã€å·¦ã‹ã‚‰6番目をé¸ã¶
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â– â– â– â– â– â– â– â– â–
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
↓上ã‹ã‚‰2番目ã€å·¦ã‹ã‚‰2番目をé¸ã¶
â–¡â– â–¡â–¡â–¡â– â–¡â–¡â–¡
â– â– â– â– â– â– â–¡â–¡â–¡
â–¡â– â–¡â–¡â–¡â– â–¡â–¡â–¡
â– â– â– â– â– â– â– â– â–
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â–¡â–¡
↓上ã‹ã‚‰6番目ã€å·¦ã‹ã‚‰8番目をé¸ã¶
â–¡â– â–¡â–¡â–¡â– â–¡â–¡â–¡
â– â– â– â– â– â– â–¡â–¡â–¡
â–¡â– â–¡â–¡â–¡â– â–¡â–¡â–¡
â– â– â– â– â– â– â– â– â–
â–¡â–¡â–¡â–¡â–¡â– â–¡â– â–¡
â–¡â–¡â–¡â–¡â–¡â– â– â– â–
â–¡â–¡â–¡â–¡â–¡â– â–¡â– â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â– â–¡
â–¡â–¡â–¡â–¡â–¡â– â–¡â– â–¡
ã‚ãªãŸã¯ä¸Šã‹ã‚‰i番目ã§å·¦ã‹ã‚‰j番目ã®ãƒžã‚¹ã®è‰²ãŒAi,jã§ã‚るグリッドを作りãŸã„。 作るã“ã¨ãŒå¯èƒ½ã‹ã©ã†ã‹ã‚’判定ã›ã‚ˆã€‚å¯èƒ½ãªå ´åˆã¯ã€é¸ã¶ã¹ãマスã®å ´æ‰€ã¨é †ç•ªã‚’求ã‚よ。
入力ã¯ä»¥ä¸‹ã®å½¢å¼ã§ä¸Žãˆã‚‰ã‚Œã‚‹ã€‚
N
A1,1 A1,2 ... A1,N
A2,1 A2,2 ... A2,N
...
AN,1 AN,2 ... AN,N
Ai,jãŒ'o'ã§ã‚ã‚‹ã¨ãã¯ä¸Šã‹ã‚‰i番目ã€å·¦ã‹ã‚‰j番目ã®ãƒžã‚¹ãŒç™½è‰²ã§ã‚ã‚‹ã“ã¨ã‚’表ã—ã€'x'ã®ã¨ãã¯é»’色ã®ãƒžã‚¹ã§ã‚ã‚‹ã“ã¨ã‚’表ã™ã€‚
入力ã¯ä»¥ä¸‹ã®æ¡ä»¶ã‚’満ãŸã™ã€‚
ä¸å¯èƒ½ãªå ´åˆã¯-1ã¨1è¡Œã«å‡ºåŠ›ã›ã‚ˆã€‚ å¯èƒ½ãªå ´åˆã¯1行目ã«é¸ã¶ãƒžã‚¹ã®å€‹æ•°ã‚’出力ã—〠i×2行目ã«ã¯i番目ã«é¸æŠžã™ã‚‹ãƒžã‚¹ãŒä¸Šã‹ã‚‰ä½•ç•ªç›®ãªã®ã‹ã‚’〠i×2+1行目ã«ã¯i番目ã«é¸æŠžã™ã‚‹ãƒžã‚¹ãŒå·¦ã‹ã‚‰ä½•ç•ªç›®ãªã®ã‹ã‚’出力ã›ã‚ˆã€‚ 一æ„ã«å®šã¾ã‚‰ãªã„å ´åˆã¯è¾žæ›¸é †ã§æœ€å°ã«ãªã‚‹ã‚ˆã†ã«ã›ã‚ˆã€‚
5 oxooo oxooo oxooo xxxxx oxooo
1 4 2
9 oxoooooxo oxxxxxxxx oxoooooxo xxxxxxxxx oxoxooooo oxxxxxxxx oxoxoxooo oxoxxxxxx oxoxoxooo
4 4 2 2 8 6 4 8 6
3 oxx oxx ooo
-1