ã‚ュゥã¹ãˆã¯ãªã‹ãªã‹å¥‘ç´„ã‚’çµã‚“ã§ãã‚Œãªã„鹿目ã¾ã©ã‹ã«ã—ã³ã‚Œã‚’切らã›ã¦ï¼Œã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ゲームã¨ç§°ã—ã¦ä½å€‰æåã¨ç¾Žæ¨¹ã•ã‚„ã‹ã®ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº« (é‚) ã‚’ W 列 H 段ã®ãƒãƒƒã‚«ãƒ¼ã®ä¸ã«éš ã—ã¦ã—ã¾ã£ãŸï¼Žãã“ã§ï¼Œã¾ã©ã‹ã¯æåã¨ã•ã‚„ã‹ã‚’助ã‘出ã—ãŸã„.ã—ã‹ã—,契約をçµã°ãšã«åŠ©ã‘ã‚‹ã«ã¯ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã®å£ã‚’æ“作ã—㦠2 人ã®ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ã‚’,指定ã•ã‚ŒãŸãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã«æ£ã—ã移ã•ãªã‘ã‚Œã°ãªã‚‰ãªã„.ãƒãƒƒã‚«ãƒ¼ã¯ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ãŒ W 列 H 段ã«ä¸¦ã¶ã“ã¨ã§æ§‹æˆã•ã‚Œï¼Œéš£ã‚Šåˆã†ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã¯å£ã§ä»•åˆ‡ã‚‰ã‚Œã¦ã„る.
ã¾ã©ã‹ã¯ï¼Œ1 回ã®æ“作ã§ã„ãšã‚Œã‹ã®éš£ã‚Šã‚ã£ãŸ 2 ã¤ã®ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã®å£ã‚’å–り除ãã‹å–り付ã‘ã‚‹ã“ã¨ãŒã§ãる.ãŸã ã—,ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã®å£ã‚’é–‹ã‘ã‚‹ã«ã¯åˆ¶ç´„ãŒã‚り,å„ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã‹ã‚‰éš£æŽ¥ã™ã‚‹ä¸Šä¸‹å·¦å³ã®å£ã®ã†ã¡ï¼Œé«˜ã€… 2 æžšã¾ã§ã®å£ã—ã‹åŒæ™‚ã«é–‹ã‘ã¦ãŠãã“ã¨ã¯ã§ããªã„.ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã«ã¯ä¸Šã®æ®µã‹ã‚‰ä¸‹ã®æ®µã«å‘ã‹ã£ã¦é‡åŠ›ãŒåƒã„ã¦ã„る.ソウルジェムã®ä¸èº«ã¯æ¶²ä½“ã¨åŒã˜ã‚ˆã†ãªå‹•ãã‚’ã—,隣りã‚ã£ãŸ 2 ã¤ã®ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã®å£ãŒå–り除ã‹ã‚Œã¦ã„る時,åŒã˜é«˜ã•ã§ã‚ã‚Œã°äº’ã„ã«åŒã˜é‡ã«ãªã‚Šï¼Œé•ã†é«˜ã•ã§ã‚ã‚Œã°ä½Žã„æ–¹ã¸ç§»å‹•ã™ã‚‹ï¼Žã™ã¹ã¦ã®æ“作ãŒçµ‚ã‚ã£ãŸæ™‚ã«æŒ‡å®šã•ã‚ŒãŸ 2 ã¤ã®ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã«æ£ã—ã„組ã¿åˆã‚ã›ã§ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ãŒã™ã¹ã¦å…¥ã£ã¦ã„ã‚Œã°ã¾ã©ã‹ã®å‹åˆ©ã¨ãªã‚‹ï¼Žã¾ãŸï¼Œä¸€éƒ¨ã®ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã¯ç©¢ã‚Œã¦ãŠã‚Šï¼Œãã®ä¸ã¸ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ãŒå…¥ã£ã¦ã—ã¾ã†ã¨å¤§å¤‰ãªã“ã¨ã«ãªã£ã¦ã—ã¾ã†ã®ã§ï¼Œãã®ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã¯ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ã®ç§»å‹•ã®ãŸã‚ã«ä½¿ã†ã“ã¨ã¯ã§ããªã„.
最å°ã§ä½•åº¦ã®æ“作を行ãˆã°ã¾ã©ã‹ã¯ 2 人を救ã„ã ã™ã“ã¨ãŒã§ãã‚‹ã‹ã‚’求ã‚よ.
入力ã¯ä»¥ä¸‹ã®å½¢å¼ã§ä¸Žãˆã‚‰ã‚Œã‚‹ï¼Ž
H\ W\\ s_{11}\ s_{12}\ … s_{1W}\\ s_{21}\ s_{22}\ … s_{2W}\\ …\\ s_{H1}\ s_{H2}\ … s_{HW}\\
H ã¯ãƒãƒƒã‚«ãƒ¼ã®æ®µæ•°ï¼ŒW ã¯ãƒãƒƒã‚«ãƒ¼ã®åˆ—æ•°ã§ã‚る.s_{ij} ã¯ä¸Šã‹ã‚‰ i 段目ã®å·¦ã‹ã‚‰ j 列目ã®ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã®çŠ¶æ…‹ã‚’表ã™ï¼Žæåã®ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ãŒå…¥ã£ã¦ã„ã‚‹ã¨ã㯠'K'
ã§ã‚り,ã•ã‚„ã‹ã®ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ãŒå…¥ã£ã¦ã„ã‚‹ã¨ã㯠'S'
,æåã®ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ã‚’移ã™ã¹ããƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã§ã‚ã‚‹ã¨ã㯠'k'
,ã•ã‚„ã‹ã®ã‚½ã‚¦ãƒ«ã‚¸ã‚§ãƒ ã®ä¸èº«ã‚’移ã™ã¹ããƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã§ã‚ã‚‹ã¨ã㯠's'
,穢れãŸãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã§ã‚ã‚‹ã¨ã㯠'#'
,ãれ以外ã®ãƒãƒƒã‚«ãƒ¼ãƒœãƒƒã‚¯ã‚¹ã§ã‚ã‚‹ã¨ã㯠'.'
ã§ã‚る.
CONTRACT
ã¨å‡ºåŠ›ã›ã‚ˆï¼Ž
'#'
, '.'
, 'S'
, 'K'
, 's'
, 'k'
ã®ã„ãšã‚Œã‹ã§ã‚る.'S'
ã§ã‚るよã†ãª i, j ãŒã¡ã‚‡ã†ã© 1 ã¤ã ã‘å˜åœ¨ã™ã‚‹ï¼Ž'K'
ã§ã‚るよã†ãª i, j ãŒã¡ã‚‡ã†ã© 1 ã¤ã ã‘å˜åœ¨ã™ã‚‹ï¼Ž's'
ã§ã‚るよã†ãª i, j ãŒã¡ã‚‡ã†ã© 1 ã¤ã ã‘å˜åœ¨ã™ã‚‹ï¼Ž'k'
ã§ã‚るよã†ãª i, j ãŒã¡ã‚‡ã†ã© 1 ã¤ã ã‘å˜åœ¨ã™ã‚‹ï¼Ž4 4 .S.. K... .... ..sk
9
5 5 .S.K. ..#.. .###. ..#.. .k.s.
CONTRACT
8 5 S.... ####K ##... #..## #..## ##k## #...# #.s.#
19
8 5 S.... ####K ##... ##.## ##.## ##k## #...# #.s.#
CONTRACT
10 10 .......... ##......## #K......S# .......... .......... .#..##..#. ..##..##.. .......... .......... ....s.k...
22
3 3 S.s K.. ..k
CONTRACT