s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
int64
0
100
memory
stringlengths
4
6
code_size
int64
15
14.7k
code
stringlengths
15
14.7k
problem_id
stringlengths
6
6
problem_description
stringlengths
358
9.83k
input
stringlengths
2
4.87k
output
stringclasses
807 values
__index_level_0__
int64
1.1k
1.22M
s608285616
p00066
u964040941
1490417972
Python
Python3
py
Accepted
20
7344
467
c = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]] while True: try: S = input() except EOFError: break for i in c: o = True x = True for j in i: if S [j] != 'o': o = False if S [j] != 'x': x = False if o: print('o') break elif x: print('x') break else: print('d')
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,341
s033272468
p00066
u462831976
1493167789
Python
Python3
py
Accepted
30
7548
661
# -*- coding: utf-8 -*- import sys import os import re def is_win(A, B, C, sign): if A[0] == A[1] == A[2] == sign or B[0] == B[1] == B[2] == sign or C[0] == C[1] == C[2] == sign: return True elif A[0] == B[0] == C[0] == sign or A[1] == B[1] == C[1] == sign or A[2] == B[2] == C[2] == sign: return True elif A[0] == B[1] == C[2] == sign or A[2] == B[1] == C[0] == sign: return True else: return False for s in sys.stdin: s = s.strip() A = s[0:3] B = s[3:6] C = s[6:9] if is_win(A, B, C, 'o'): print('o') elif is_win(A, B, C, 'x'): print('x') else: print('d')
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,342
s289808136
p00066
u546285759
1495624645
Python
Python3
py
Accepted
20
7372
465
while True: try: hoge = input() except: break ans = "d" for i in range(3): if "ooo" == hoge[i*3:i*3+3] or "ooo" == hoge[i::3]: ans = "o" break elif "xxx" == hoge[i*3:i*3+3] or "xxx" == hoge[i::3]: ans = "x" break if hoge[0::4] == "ooo" or hoge[2:7:2] == "ooo": ans = "o" elif hoge[0::4] == "xxx" or hoge[2:7:2] == "xxx": ans = "x" print(ans)
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,343
s600824708
p00066
u811733736
1503449762
Python
Python3
py
Accepted
30
7568
2,357
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0066 """ import sys def prepare_board(size=3): return [[1]*size for _ in range(size)] def check_horizontal(status): dp = prepare_board() for y in range(len(status)): for x in range(1, len(status[0])): if status[y][x] == status[y][x-1]: dp[y][x] = dp[y][x-1] + 1 if dp[y][x] == 3: if status[y][x] != 's': return status[y][x] return 'd' def check_vertical(status): dp = prepare_board() for y in range(1, len(status)): for x in range(len(status[0])): if status[y][x] == status[y-1][x]: dp[y][x] = dp[y-1][x] + 1 if dp[y][x] == 3: if status[y][x] != 's': return status[y][x] return 'd' def check_diagonal(status): # ????????????????????????????§??????????????????§?????? dp = prepare_board() for y in range(1, len(status)): for x in range(1, len(status[0])): if status[y][x] == status[y-1][x-1]: dp[y][x] = dp[y-1][x-1] + 1 if dp[y][x] == 3: if status[y][x] != 's': return status[y][x] # ????????????????????????????§??????????????????§?????? dp = prepare_board() for y in range(1, len(status)): for x in range(len(status[0])-2, -1, -1): if status[y][x] == status[y-1][x+1]: dp[y][x] = dp[y-1][x+1] + 1 if dp[y][x] == 3: if status[y][x] != 's': return status[y][x] return 'd' def solve(status): result = check_horizontal(status) if result != 'd': return result result = check_vertical(status) if result != 'd': return result return check_diagonal(status) def main(args): for line in sys.stdin: # ??\???????????????3x3?????¶????????????????????????????§£?????¢??°????????? status = [] line = line.strip() status.append(list(line[:3])) status.append(list(line[3:6])) status.append(list(line[6:])) result = solve(status) # ?????????????¨? print(result) if __name__ == '__main__': main(sys.argv[1:])
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,344
s136368541
p00066
u957021183
1505109317
Python
Python3
py
Accepted
20
7524
989
# Aizu Problem 0066: Tic-Tac-Toe # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def check_triple(triple): # check whether a triple of values is a winning position: return len(set(triple)) == 1 and triple[0] != 's' def isSolved(board): # first check if there's a winner: # check rows: for row in board: if check_triple(row): return row[0] # check columns: for col in range(3): column = [board[row][col] for row in range(3)] if check_triple(column): return column[0] # check diagonals: if check_triple([board[i][i] for i in range(3)]): return board[0][0] if check_triple([board[i][2-i] for i in range(3)]): return board[2][0] # # no winner: return 'd' for line in sys.stdin: string = line.strip() board = [string[3*i:3*i+3] for i in range(3)] print(isSolved(board))
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,345
s918159333
p00066
u150984829
1514697360
Python
Python3
py
Accepted
20
5564
234
import sys t={'o':1,'x':-1,'s':0} for l in sys.stdin: d=[t[s]for s in l.strip()] a=[sum(d[0:3]),sum(d[3:6]),sum(d[6:]),sum(d[0::3]),sum(d[1::3]),sum(d[2::3]),sum(d[0::4]),sum(d[2:8:2])] print('o'if 3 in a else'x'if -3 in a else'd')
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,346
s490277370
p00066
u150984829
1514698005
Python
Python3
py
Accepted
20
5572
210
import sys t={'o':1,'x':-1,'s':0} for l in sys.stdin: d=[t[s]for s in l.strip()] a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])] print('o'if 3 in a else'x'if -3 in a else'd')
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,347
s030863551
p00066
u150984829
1514698895
Python
Python3
py
Accepted
20
5572
206
import sys for l in sys.stdin: d=[{'o':1,'x':-1,'s':0}[s]for s in l.strip()] a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])] print('o'if 3 in a else'x'if -3 in a else'd')
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,348
s055087907
p00066
u024715419
1518501509
Python
Python3
py
Accepted
20
5560
546
while True: try: s = input() if s[4] != "s": if (s[0] == s[4] and s[0] == s[8]) or (s[2] == s[4] and s[2] == s[6]): print(s[4]) continue for i in range(3): if s[i] != "s" and s[i] == s[i + 3] and s[i] == s[i + 6]: print(s[i]) break elif s[3*i] != "s" and s[3*i] == s[3*i + 1] and s[3*i] == s[3*i + 2]: print(s[3*i]) break else: print("d") except: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,349
s795698655
p00066
u043254318
1518718262
Python
Python3
py
Accepted
20
5576
1,012
def get_input(): while True: try: yield ''.join(input()) except EOFError: break N = list(get_input()) for l in range(len(N)): table = [[0 for i in range(3)] for j in range(3)] S = N[l] ans = "d" for i in range(9): if S[i] == "o": table[i // 3][i % 3] = 1 elif S[i] == "x": table[i // 3][i % 3] = -1 for i in range(3): s = 0 for j in range(3): s += table[i][j] if s == 3: ans = "o" elif s == -3: ans = "x" for i in range(3): s = 0 for j in range(3): s += table[j][i] if s == 3: ans = "o" elif s == -3: ans = "x" s = table[0][0] + table[1][1] + table[2][2] if s == 3: ans = "o" elif s == -3: ans = "x" s = table[0][2] + table[1][1] + table[2][0] if s == 3: ans = "o" elif s == -3: ans = "x" print(ans)
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,350
s378456791
p00066
u150984829
1520109783
Python
Python3
py
Accepted
20
5572
196
import sys for l in sys.stdin: d=[{'o':1,'x':-1,'s':0}[s]for s in l.strip()] a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])] print(['dx'[-3 in a],'o'][3 in a])
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,351
s000059161
p00066
u150984829
1520109918
Python
Python3
py
Accepted
20
5568
194
import sys for e in sys.stdin: d=[{'o':1,'x':-1,'s':0}[s]for s in e.strip()] a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])] print('dxo'[(-3in a)+(3in a)*2])
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,352
s745477455
p00066
u352394527
1527542576
Python
Python3
py
Accepted
20
5564
566
def check(s): for i in (0, 3, 6): #横 if s[i] != "s" and s[i] == s[i + 1] and s[i + 1] == s[i + 2]: print(s[i]) return for i in (0, 1, 2): #縦 if s[i] != "s" and s[i] == s[i + 3] and s[i + 3] == s[i + 6]: print(s[i]) return if s[0] != "s" and s[0] == s[4] and s[4] == s[8]: #斜め1 print(s[0]) return if s[2] != "s" and s[2] == s[4] and s[4] == s[6]: #斜め2 print(s[2]) return print("d") #それ以外なら引き分け while True: try: check(input()) except EOFError: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,353
s957936453
p00066
u136916346
1527949316
Python
Python3
py
Accepted
30
5568
343
import sys def ttt(o): if (o[0]==o[4]==o[8] or o[2]==o[4]==o[6]) and o[4]!="s": return o[4] for i in range(3): if o[i*3]!="s" and o[i*3]==o[i*3+1]==o[i*3+2]: return o[i*3] if o[i]!="s" and o[i]==o[i+3]==o[i+6]: return o[i] return "d" [print(ttt(j)) for j in [i for i in sys.stdin]]
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,354
s035684499
p00066
u847467233
1529148616
Python
Python3
py
Accepted
20
5572
697
# AOJ 0066 Tic Tac Toe # Python3 2018.6.15 bal4u arr = [[0 for r in range(3)] for c in range(3)] koma = { 'o':1, 'x':-1, 's':0 } while True: try: a = list(input()) except: break for i in range(len(a)): arr[i//3][i%3] = koma[a[i]] end = False for r in range(3): d = 0; for c in range(3): d += arr[r][c] if d == 3 or d == -3: end = True break if not end: for c in range(3): d = 0; for r in range(3): d += arr[r][c]; if d == 3 or d == -3: end = True break if not end: d = arr[0][0]+arr[1][1]+arr[2][2] if d == 3 or d == -3: end = True if not end: d = arr[0][2]+arr[1][1]+arr[2][0] if d == 3: print('o') elif d == -3: print('x') else: print('d')
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,355
s791434542
p00066
u847467233
1529150235
Python
Python3
py
Accepted
20
5564
344
# AOJ 0066 Tic Tac Toe # Python3 2018.6.15 bal4u def check(a): for koma in ['o', 'x']: for i in range(3): if a[i:9:3].count(koma) == 3 or a[3*i:3*i+3].count(koma) == 3: return koma if a[0:9:4].count(koma) == 3 or a[2:7:2].count(koma) == 3: return koma return 'd' while True: try: print(check(list(input()))) except EOFError: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,356
s818387822
p00066
u759949288
1352628486
Python
Python
py
Accepted
20
4248
407
import sys def win(c, line): for i in range(0, 9, 3): if all(p == c for p in line[i:i + 3:1]): return True for i in range(3): if all(p == c for p in line[i:i + 9:3]): return True if all(p == c for p in line[0::4]): return True if all(p == c for p in line[2:8:2]): return True return False; for line in sys.stdin: for c in ['o', 'x']: if win(c, line): print c break else: print 'd'
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,357
s575908112
p00066
u647766105
1356473305
Python
Python
py
Accepted
20
4248
497
import sys for line in sys.stdin.readlines(): result="d" for i in xrange(3): if not line[3*i]=="s" and line[3*i]==line[3*i+1] and line[3*i]==line[3*i+2]: result=line[3*i] if not line[i]=="s" and line[i]==line[i+3] and line[i]==line[i+6]: result=line[i] if not line[0]=="s" and line[0]==line[4] and line[0]==line[8]: result=line[0] if not line[2]=="s" and line[2]==line[4] and line[2]==line[6]: result=line[2] print result
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,358
s317542990
p00066
u104911888
1364468356
Python
Python
py
Accepted
20
4276
808
while (1): try: s=raw_input() except EOFError: break B=False if s[0]==s[4]==s[8]=="o": print "o" B=True elif s[0]==s[4]==s[8]=="x": print "x" B=True if s[2]==s[4]==s[6]=="o": print "o" B=True elif s[2]==s[4]==s[6]=="x": print "x" B=True for i in range(3): if s[i*3]==s[i*3+1]==s[i*3+2]=="o": print "o" B=True break elif s[i*3]==s[i*3+1]==s[i*3+2]=="x": print "x" B=True break elif s[i]==s[i+3]==s[i+6]=="o": print "o" B=True break elif s[i]==s[i+3]==s[i+6]=="x": print "x" B=True break if B==False: print "d"
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,359
s840617471
p00066
u104911888
1367482269
Python
Python
py
Accepted
20
4240
315
while True: try: s=raw_input() except EOFError: break L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[(0,4\ ,8),(2,4,6)] for i,j,k in L: if s[i]==s[j]==s[k]!="s": print "o" if s[i]=="o" else "x" break else: print "d"
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,360
s361381817
p00066
u915761101
1369217726
Python
Python
py
Accepted
10
4244
375
def get_winner(s): for p in ['o','x']: for i in xrange(3): win_h=True win_v=True for j in xrange(3): if s[i*3+j]!=p: win_h=False if s[j*3+i]!=p: win_v=False if win_h or win_v: return p if p==s[0]==s[4]==s[8] or p==s[2]==s[4]==s[6]: return p return 'd' while 1: try: s=raw_input() print get_winner(s) except EOFError: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,361
s861979685
p00066
u542421762
1370923205
Python
Python
py
Accepted
10
4256
640
import sys def solv(b): if judge(b, 0, 1, 2): return b[0] elif judge(b, 3, 4, 5): return b[3] elif judge(b, 6, 7, 8): return b[6] elif judge(b, 0, 3, 6): return b[0] elif judge(b, 1, 4, 7): return b[1] elif judge(b, 2, 5, 8): return b[2] elif judge(b, 0, 4, 8): return b[0] elif judge(b, 2, 4, 6): return b[2] else: return 'd' def judge(b, i, j, k): if b[i] == b[j] == b[k] and not b[i] == 's': return True else: return False for line in sys.stdin: boad = list(line.rstrip()) print solv(boad)
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,362
s351154479
p00066
u782850731
1377505954
Python
Python
py
Accepted
20
4280
714
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin condition = ('ooo', 'xxx') for line in stdin: if line[0:3] in condition: win = line[0] elif line[3:6] in condition: win = line[3] elif line[6:9] in condition: win = line[6] elif line[0:9:3] in condition: win = line[0] elif line[1:9:3] in condition: win = line[1] elif line[2:9:3] in condition: win = line[2] elif line[0:9:4] in condition: win = line[0] elif line[2:7:2] in condition: win = line[2] else: win = 'd' print(win)
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,363
s534909255
p00066
u093607836
1382882398
Python
Python
py
Accepted
20
4380
581
import sys,itertools ans = ['xxx ',' xxx ',' xxx','x x x ',' x x x ',' x x x','x x x',' x x x '] for s in sys.stdin: s = s.strip() o = [True if c == 'o' else False for c in s] x = [True if c == 'x' else False for c in s] o = list(itertools.repeat(0,len(ans))) x = list(itertools.repeat(0,len(ans))) out = 'd' for i,j in itertools.product(xrange(len(ans)),xrange(len(ans[0]))): if ans[i][j] == 'x': if s[j] == 'o': o[i] = o[i] + 1 if s[j] == 'x': x[i] = x[i] + 1 if 3 in o: print 'o' elif 3 in x: print 'x' else: print 'd'
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,364
s192431689
p00066
u912237403
1390005897
Python
Python
py
Accepted
10
4228
350
import sys for s in sys.stdin: c="d" for i in range(3): a=s[i] if a!="s"and a==s[i+3]==s[i+6]: c=a break j=i*3 a=s[j] if a!="s"and a==s[j+1]==s[j+2]: c=a break else: a=s[4] if a!="s"and (s[0]==a==s[8] or s[2]==a==s[6]):c=a print c
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,365
s637008420
p00066
u912237403
1390007757
Python
Python
py
Accepted
20
4220
287
import sys x=["ooo","xxx"] for s in sys.stdin: c="d" for i in range(3): if s[i:9:3]in x: c=s[i] break j=i*3 if s[j:j+3]in x: c=s[j] break else: if s[0::4] in x or s[2:7:2] in x:c=s[4] print c
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,366
s241553658
p00066
u912237403
1390009805
Python
Python
py
Accepted
10
4216
307
import sys def f(a,b,c): return a if a!="s"and a==b==c else 0 for s in sys.stdin: for i in range(3): c=f(*s[i:9:3]) if c: break j=i*3 c=f(*s[j:j+3]) if c: break else: a=s[4] if f(*s[0:9:4])or f(*s[2:7:2]):c=a else:c="d" print c
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,367
s460084471
p00066
u912237403
1390009968
Python
Python
py
Accepted
20
4216
297
import sys def f(a,b,c): return a if a!="s"and a==b==c else 0 for s in sys.stdin: for i in range(3): c=f(*s[i:9:3]) if c: break j=i*3 c=f(*s[j:j+3]) if c: break else: a=s[4] c=a if f(*s[0:9:4])or f(*s[2:7:2]) else "d" print c
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,368
s342619233
p00066
u912237403
1390010083
Python
Python
py
Accepted
10
4220
297
import sys def f(a,b,c): return a if a!="s"and a==b==c else 0 for s in sys.stdin: for i in range(3): c=f(*s[i:9:3]) if c: break j=i*3 c=f(*s[j:j+3]) if c: break else: a=s[4] c=a if f(*s[0:9:4])or f(*s[2:7:2]) else "d" print c
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,369
s309343580
p00066
u912237403
1390010292
Python
Python
py
Accepted
10
4216
285
import sys def f(a,b,c): return a if a!="s"and a==b==c else 0 for s in sys.stdin: for i in range(3): c=f(*s[i:9:3]) if c: break j=i*3 c=f(*s[j:j+3]) if c: break else: c=s[4] if f(*s[0:9:4])or f(*s[2:7:2]) else "d" print c
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,370
s236445348
p00066
u633068244
1393693949
Python
Python
py
Accepted
10
4220
573
while True: try: a = raw_input() if a[::4] == "ooo" or a[2:8:2] == "ooo": print "o" elif a[::4] == "xxx" or a[2:8:2] == "xxx": print "x" else: for i in range(3): if a[3*i:3*(i+1)] == "ooo" or a[i::3] == "ooo": print "o" break elif a[3*i:3*(i+1)] == "xxx" or a[i::3] == "xxx": print "x" break elif i == 2: print "d" except: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,371
s848503699
p00066
u708217907
1399790457
Python
Python
py
Accepted
10
4220
374
def judge(a, b, c): return a if a == b == c and a != 's' else 0 while True: try: s = raw_input() for i in range(3): result = judge(*s[i:9:3]) if result: break result = judge(*s[3*i:3*i+3]) if result: break else: result = s[4] if s[4] != 's' and (judge(*s[0:9:4]) or judge(*s[2:7:2])) else 'd' except: break print result
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,372
s874801176
p00066
u436634575
1402301018
Python
Python3
py
Accepted
30
6716
310
while True: try: ban = input() except EOFError: break s = [ban[:3], ban[3:6], ban[6:]] s += map(''.join, zip(*s)) s += [ban[0]+ban[4]+ban[8]] + [ban[2]+ban[4]+ban[6]] if 'ooo' in s: print('o') elif 'xxx' in s: print('x') else: print('d')
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,373
s284238812
p00066
u187074069
1595170540
Python
Python3
py
Accepted
20
5560
745
while True: try: k = list(input()) ans = 'd' lst1 = [k[:3], k[3:6], k[6:]] lst2 = [k[::3], k[1::3], k[2::3]] if k[4] != 's': if k[0] == k[4] and k[4] == k[8]: ans = k[4] elif k[2] == k[4] and k[4] == k[6]: ans = k[4] for i in lst1: if i.count('o') == 3: ans = 'o' elif i.count('x') == 3: ans = 'x' else: pass for i in lst2: if i.count('o') == 3: ans = 'o' elif i.count('x') == 3: ans = 'x' else: pass print(ans) except EOFError: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,374
s511609832
p00066
u260980560
1590284380
Python
Python3
py
Accepted
20
5572
537
import sys readlines = sys.stdin.readlines write = sys.stdout.write P = [ (0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6), ] def solve(): for line in readlines(): s = line.strip() for a, b, c in P: if s[a] == s[b] == s[c]: if s[a] == 'o': write("o\n") break elif s[a] == 'x': write("x\n") break else: write("d\n") solve()
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,375
s068455232
p00066
u630911389
1583686294
Python
Python3
py
Accepted
20
5572
1,134
table = [[''] * 3 for i in range(3)] def ans(): r = 0 c = 1 # 横 while(r < 3): char = table[r][0] if char != 's': c = 1 while(c < 3): if table[r][c] != char: break if table[r][c] == char and c + 1 >= 3: return char c += 1 r += 1 # 縦 r = 1 c = 0 while(c < 3): char = table[0][c] if char != 's': r = 1 while(r < 3): if table[r][c] != char: break if table[r][c] == char and r + 1 >= 3: return char r += 1 c += 1 # 斜め char = table[1][1] if char != 's': if (table[0][0] == char and table[2][2] == char) or (table[0][2] == char and table[2][0] == char): return char return 'd' while(1): try: s = input() for i in range(0,3): for j in range(0,3): table[i][j] = s[(i * 3) + j] print(ans()) except: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,376
s992287345
p00066
u606731189
1577254480
Python
Python3
py
Accepted
20
5560
682
def cross(s): if s[0]==s[4]==s[8] and s[0]!="s": print(s[0]) return True elif s[2]==s[4]==s[6] and s[2]!="s": print(s[2]) return True else: return False def side(s): for i in range(0,len(s),3): if s[i]==s[i+1]==s[i+2] and s[i]!="s": print(s[i]) return True return False def ver(s): for i in range(3): if s[i]==s[i+3]==s[i+6] and s[i]!="s": print(s[i]) return True return False while True: try: s=list(map(str,input())) except EOFError: break if cross(s)==side(s)==ver(s)==False: print("d")
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,377
s704832385
p00066
u803862921
1573210086
Python
Python3
py
Accepted
20
5556
426
while True: try: s = input().rstrip() except: break win = None for i, j, k in ((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)): chk = s[i] + s[j] + s[k] if chk == "ooo": win = "o" break elif chk == "xxx": win = "x" break if win: print(win) else: print("d")
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,378
s371308290
p00066
u824708460
1567136236
Python
Python3
py
Accepted
20
5560
330
def f(s): for t in ['o', 'x']: if s[::4].count(t) == 3 or s[2:7:2].count(t) == 3: return t for i in range(3): if s[i::3].count(t) == 3 or s[3 * i:3 * i + 3].count(t) == 3: return t return 'd' while 1: try: print(f(input())) except: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,379
s577532681
p00066
u548252256
1561645757
Python
Python3
py
Accepted
30
5596
1,345
if __name__ == '__main__': while True: try: line = list(input()) ans = "d" if line[0] == "o" and line[4] == "o" and line[8] == "o": ans = "o" elif line[2] == "o" and line[4] == "o" and line[6] == "o": ans = "o" elif line[0] == "o" and line[3] == "o" and line[6] == "o": ans = "o" elif line[1] == "o" and line[4] == "o" and line[7] == "o": ans = "o" elif line[2] == "o" and line[5] == "o" and line[8] == "o": ans = "o" elif line[0] == "o" and line[1] == "o" and line[2] == "o": ans = "o" elif line[3] == "o" and line[4] == "o" and line[5] == "o": ans = "o" elif line[6] == "o" and line[7] == "o" and line[8] == "o": ans = "o" if line[0] == "x" and line[4] == "x" and line[8] == "x": ans = "x" elif line[2] == "x" and line[4] == "x" and line[6] == "x": ans = "x" elif line[0] == "x" and line[3] == "x" and line[6] == "x": ans = "x" elif line[1] == "x" and line[4] == "x" and line[7] == "x": ans = "x" elif line[2] == "x" and line[5] == "x" and line[8] == "x": ans = "x" elif line[0] == "x" and line[1] == "x" and line[2] == "x": ans = "x" elif line[3] == "x" and line[4] == "x" and line[5] == "x": ans = "x" elif line[6] == "x" and line[7] == "x" and line[8] == "x": ans = "x" print(ans) except EOFError: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,380
s853038754
p00066
u990228206
1553153050
Python
Python3
py
Accepted
20
5560
568
while 1: try: s=input() if s[0]==s[1]==s[2]!="s": print(s[0]) elif s[3]==s[4]==s[5]!="s": print(s[3]) elif s[6]==s[7]==s[8]!="s": print(s[6]) elif s[0]==s[3]==s[6]!="s": print(s[0]) elif s[1]==s[4]==s[7]!="s": print(s[1]) elif s[2]==s[5]==s[8]!="s": print(s[2]) elif s[0]==s[4]==s[8]!="s": print(s[0]) elif s[2]==s[4]==s[6]!="s": print(s[2]) else: print("d") except:break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,381
s824367626
p00066
u563075864
1544584951
Python
Python3
py
Accepted
20
5568
486
while(1): try: faces = [1 if i == "o" else 0 for i in list(input())] hori = [sum(faces[0:3]),sum(faces[3:6]),sum(faces[6:9])] vert = [sum(faces[0:7:3]),sum(faces[1:8:3]),sum(faces[2:9:3])] diag = [sum(faces[0:9:4]),sum(faces[2:7:2])] hori.extend(vert) hori.extend(diag) if 3 in hori: print("o") elif 0 in hori: print("x") else: print("d") except EOFError: break
p00066
<H1>三目並べ</H1> <p> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図1〜図3 を参照) </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</td> </tr> </table> </center> <br/> <p> 三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
ooosxssxs xoosxsosx ooxxxooxo
o x d
11,382
s081098074
p00067
u197615397
1531228024
Python
Python3
py
Accepted
30
6016
756
from collections import deque dq = deque() append, popleft = dq.append, dq.popleft try: while True: a = [[0]*14] + [[0]+list(map(int,input()))+[0] for _ in [0]*12] + [[0]*14] result = 0 for y in range(1, 13): for x in filter(lambda x: a[y][x], range(1, 13)): result += 1 a[y][x] = 0 dq.clear() append((x, y)) while dq: cx, cy = popleft() for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0)): if a[cy+dy][cx+dx]: a[cy+dy][cx+dx] = 0 append((cx+dx, cy+dy)) print(result) input() except EOFError: pass
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,383
s793887363
p00067
u647694976
1559031025
Python
Python3
py
Accepted
30
5580
381
c=0 def f(a,x,y): if 0<=x<12 and 0<=y<12 and a[y][x]=='1': a[y][x]='0' for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:f(a,x+dx,y+dy) while 1: try: if c:input() except:break a = [list(input()) for _ in [0]*12] c=1;b=0 for i in range(12): for j in range(12): if a[j][i]=='1': b+=1;f(a,i,j) print(b)
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,384
s397588046
p00067
u093607836
1407609004
Python
Python3
py
Accepted
40
6756
934
import itertools def getPoint(m,x,y): if not (0 <= x < 12) or not (0 <= y < 12): return 0 return m[y][x] def setPoint(m,x,y,v): m[y][x] = v while 1: try: m = [list(map(int,input().strip())) for _ in range(12)] count = 0 empty = False while not empty: empty = True for x,y in itertools.product(range(12),repeat=2): if(getPoint(m,x,y)): count += 1 empty = False q = [] q.append((x,y)) while q != []: p = q.pop() if(getPoint(m,p[0],p[1])): setPoint(m,p[0],p[1],0) for o in [(1,0),(-1,0),(0,1),(0,-1)]: q.append((p[0] + o[0], p[1] + o[1])) print(count) input() except: exit()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,385
s853443696
p00067
u193025715
1408888805
Python
Python3
py
Accepted
30
6744
768
def fill(x, y, board): board[y][x] = 2 points = [[y, x + 1], [y, x - 1], [y + 1, x], [y - 1, x]] if y == 0: points.remove([y-1, x]) elif y == 11: points.remove([y+1, x]) if x == 0: points.remove([y, x - 1]) elif x == 11: points.remove([y, x + 1]) for p in points: if board[p[0]][p[1]] == 1: board = fill(p[1], p[0], board) return board while True: try: islands = [list(map(int, list(input()))) for i in range(12)] ans = 0 for y in range(12): for x in range(12): if islands[y][x] == 1: islands = fill(x, y, islands) ans += 1 print(ans) input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,386
s116709657
p00067
u506132575
1417227650
Python
Python
py
Accepted
20
4500
726
import itertools import sys def delete(ya,xa,lis): lis[ya][xa] = 0 move = [[-1,0],[0,-1],[1,0],[0,1]] for x,y in move: if 0<=xa+x<=11 and 0<=ya+y<=11 and lis[ya+y][xa+x]=='1': delete(ya+y,xa+x,lis) def sol(a,b,lis): for i,j in itertools.product(xrange(12),repeat=2): if lis[i][j]=='1': m[i][j] = 1 delete(i,j,lis) while True: try: l = [[ 0 for i in xrange(12) ] for j in xrange(12) ] m = [[ 0 for i in xrange(12) ] for j in xrange(12) ] d = [] for i in xrange(12): d.append(list(raw_input())) sol(0,0,d) print sum([1 for e in m for f in e if f]) raw_input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,387
s279389881
p00067
u586434734
1421758171
Python
Python
py
Accepted
20
4360
1,319
#! /usr/bin/python # -*- coding: utf-8 -*- MAX_Y = 12 MAX_X = 12 XY = ((-1, 0), (1, 0), (0, -1), (0, 1)) def main(): # input while(True): try: data = [] for j in range(MAX_Y): input_list = map(int, raw_input()) data.append(input_list) print(countIsland(data)) raw_input() except EOFError: break def countIsland(data): cnt = [0] def countIsland_(data): land = findIsland(data) if len(land) == 0: return cnt[0] else: data = sinkIsland(data, land) cnt[0] = cnt[0] + 1 return countIsland_(data) return countIsland_(data) # sink adjasent Island. def sinkIsland(data, land): if isIn(*land): if not data[land[1]][land[0]] == 0: data[land[1]][land[0]] = 0 lands = [(k[0] + land[0], k[1] + land[1]) for k in XY] for x in lands: data = sinkIsland(data, x) return data def findIsland(data): for y in range(MAX_Y): for x in range(MAX_X): if data[y][x] == 1: return (x, y) else: return () # decision inner board. def isIn(x, y): return 0<=x<MAX_X and 0<=y<MAX_Y if __name__=='__main__': main()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,388
s417762700
p00067
u567380442
1424677396
Python
Python3
py
Accepted
30
6724
598
import sys f = sys.stdin def paintout0(islands, x, y): if 0 <= x <12 and 0 <= y <12 and islands[y][x]: islands[y][x] = 0 paintout0(islands,x + 1,y) paintout0(islands,x,y + 1) paintout0(islands,x -1,y) paintout0(islands,x,y -1) while True: islands = [[int(c) for c in f.readline().strip()] for _ in range(12)] cnt =0 for y in range(len(islands)): for x in range(len(islands[0])): if islands[y][x]: cnt += 1 paintout0(islands,x,y) print(cnt) if not f.readline(): break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,389
s211155757
p00067
u873482706
1434941707
Python
Python
py
Accepted
20
4376
878
import sys def quartet(h, w): global flag if 0 <= h <= 11 and 0 <= w <= 11: if mapp[h][w] == '1': mapp[h][w] = '$' flag = True bigbang(h, w) elif mapp[h][w] == '0' or mapp[h][w] == '$': return else: return def bigbang(h, w): quartet(h, w+1) quartet(h-1,w) quartet(h, w-1) quartet(h+1, w) mapp = [] for line in sys.stdin: if not line == '\n': lis = [] for char in line.rstrip(): lis.append(char) else: mapp.append(lis) if len(mapp) == 12: flag = False count = 0 for h in range(12): for w in range(12): quartet(h, w) if flag == True: count += 1 flag = False else: print count mapp = []
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,390
s709249287
p00067
u489809100
1447517834
Python
Python
py
Accepted
20
6276
695
def fact(y, x1, x2): island[y] = island[y][:x1] + "0" + island[y][x2:] if island[y-1][x1:x2] == "1": fact(y-1, x1, x2) if island[y+1][x1:x2] == "1": fact(y+1, x1, x2) if island[y][x1-1:x2-1] == "1": fact(y, x1 - 1, x2 - 1) if island[y][x1+1:x2+1] == "1": fact(y, x1 + 1, x2 + 1) while True: island = [] for _ in xrange(12): island.append(raw_input()) island.insert(0, "00000000000000") island.append("00000000000000") for i in xrange(12): island[i+1] = "0" + island[i+1] + "0" count = 0 for i in xrange(12): for j in xrange(12): if island[i+1][j+1:j+2] == "1": fact(i+1, j+1, j+2) count += 1 print count try: raw_input() except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,391
s171004292
p00067
u140201022
1451279847
Python
Python
py
Accepted
10
6384
948
xy=[(1,0),(-1,0),(0,1),(0,-1)] bs=[(-1,-1),(-1,1),(1,1),(1,-1)] def gcd(a,b): return a if b==0 else gcd(b,a%b) def lcm(a,b): return a*b/gcd(a,b) def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0 def sol(l,a,b): q=[[a,b]] while len(q): chk=q.pop() for y,x in xy: try: t1,t2=chk[0]+y,chk[1]+x if l[t1][t2]==1 and 0<=t1<12 and 0<=t2<12: q.append([t1,t2]) l[t1][t2]=0 except: pass return l while 1: l=[] try: for i in range(12): l.append([int(x) for x in raw_input()]) ans=0 for i in range(12): for j in range(12): if l[i][j]==1: l[i][j]=0 ans+=1 l=sol(l,i,j) print ans raw_input() except: break exit()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,392
s568007095
p00067
u529386725
1452714083
Python
Python
py
Accepted
10
6384
604
N = 12 di = [1, 0, -1, 0] dj = [0, 1, 0, -1] def dfs(i, j): field[i][j] = '0' for k in xrange(4): ni = i + di[k] nj = j + dj[k] if 0 <= ni < N and 0 <= nj < N and field[ni][nj] == '1': dfs(ni, nj) return; while True: try: field = [] for i in xrange(N): field.append(list(raw_input())) cnt = 0 for i in xrange(N): for j in xrange(N): if field[i][j] == '1': dfs(i, j) cnt += 1 print cnt raw_input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,393
s041841102
p00067
u797673668
1453046148
Python
Python3
py
Accepted
30
7812
652
def search_neighbor(sea, x, y): global dir_x, dir_y for i in range(4): nx, ny = x + dir_x[i], y + dir_y[i] if not 0 <= nx < 12 or not 0 <= ny < 12: continue if sea[ny][nx]: sea[ny][nx] = 0 search_neighbor(sea, nx, ny) dir_x = (1, -1, 0, 0) dir_y = (0, 0, 1, -1) while True: sea = [[int(i) for i in input()] for _ in range(12)] count = 0 for i in range(144): x, y = i % 12, i // 12 if sea[y][x]: sea[y][x] = 0 search_neighbor(sea, x, y) count += 1 print(count) try: input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,394
s402731869
p00067
u873482706
1458455353
Python
Python3
py
Accepted
50
7476
843
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' for i in range(4): if i == 0: # U f2(x, y-1) elif i == 1: # D f2(x, y+1) elif i == 2: # R f2(x+1, y) elif i == 3: # L f2(x-1, y) def get_input(): while True: try: yield input() except EOFError: break M = [] for line in list(get_input()): if line == '': print(f1()) M = [] else: M.append(list(line)) print(f1())
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,395
s147898781
p00067
u873482706
1458455947
Python
Python3
py
Accepted
30
7624
654
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' f2(x, y-1) f2(x, y+1) f2(x+1, y) f2(x-1, y) def get_input(): while True: try: yield input() except EOFError: break M = [] for line in list(get_input()): if line == '': print(f1()) M = [] else: M.append(list(line)) print(f1())
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,396
s663956071
p00067
u873482706
1458456206
Python
Python3
py
Accepted
30
7472
613
def f1(): t = 0 for y, line in enumerate(M): for x, cell in enumerate(line): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' f2(x, y-1) f2(x, y+1) f2(x+1, y) f2(x-1, y) M = [] while True: try: line = input() if line == '': print(f1()) M = [] else: M.append(list(line)) except EOFError: print(f1()) break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,397
s482470032
p00067
u873482706
1458457214
Python
Python3
py
Accepted
30
7472
603
def f1(): t = 0 for y in range(len(M)): for x in range(len(M[0])): if M[y][x] == '1': f2(x, y) t += 1 return t def f2(x, y): if x < 0 or len(M[0]) == x or y < 0 or len(M) == y: return if M[y][x] == '1': M[y][x] = '0' f2(x, y-1) f2(x, y+1) f2(x+1, y) f2(x-1, y) M = [] while True: try: line = input() if line == '': print(f1()) M = [] else: M.append(list(line)) except EOFError: print(f1()) break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,398
s053179492
p00067
u894114233
1468563067
Python
Python
py
Accepted
10
6324
626
def check(y,x): if 0<=y<=11 and 0<=x<=11: return True return False def dfs(y,x): if g[y][x]=="0":return 0 g[y][x]="0" for i in xrange(4): nexty=y+dy[i] nextx=x+dx[i] if not check(nexty,nextx):continue if visited[nexty][nextx]==0 and g[nexty][nextx]=="1": visited[nexty][nextx]=1 dfs(nexty,nextx) return 1 dx=(1,0,-1,0) dy=(0,1,0,-1) while 1: try: g=[[] for _ in xrange(12)] for i in xrange(12): for j in raw_input(): g[i].append(j) cnt=0 visited=[[0]*12 for _ in xrange(12)] for i in xrange(12): for j in xrange(12): cnt+=dfs(i,j) print(cnt) raw_input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,399
s316488390
p00067
u685815919
1473649561
Python
Python
py
Accepted
20
6512
600
H, W = 12, 12 dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]] field = [] def solver(x, y): global field if x < 0 or y < 0 or x >= H or y >= W: return for dx, dy in dxy: if x+dx < 0 or y+dy < 0 or x+dx >= H or y+dy >= W: continue if field[x+dx][y+dy] == 1: field[x+dx][y+dy] = 0 solver(x+dx, y+dy) while True: field = [] for i in xrange(H): field.append(map(int, raw_input())) ans = 0 for x in xrange(H): for y in xrange(W): if field[x][y] == 1: solver(x, y) ans += 1 print ans try: raw_input() except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,400
s717153741
p00067
u921312486
1483089510
Python
Python3
py
Accepted
30
7716
470
import sys def solve(f, i, j): if 0<=i<12 and 0<=j<12 and f[j][i] == 1: f[j][i] = 0 for dx, dy in [[0,1],[0,-1],[1,0],[-1,0]]: solve(f, i+dx, j+dy) while True: field = [[int(c) for c in sys.stdin.readline().strip()] for _ in range(12)] ans = 0 for i in range(12): for j in range(12): if field[j][i] == 1: solve(field,i,j) ans += 1 print(ans) if not sys.stdin.readline(): break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,401
s188360211
p00067
u078042885
1486669735
Python
Python3
py
Accepted
30
7472
379
c=0 def f(a,x,y): if 0<=x<12 and 0<=y<12 and a[y][x]=='1': a[y][x]='0' for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:f(a,x+dx,y+dy) while 1: try: if c:input() except:break a = [list(input()) for _ in [0]*12] c=1;b=0 for i in range(12): for j in range(12): if a[j][i]=='1': b+=1;f(a,i,j) print(b)
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,402
s425044078
p00067
u078042885
1486670323
Python
Python3
py
Accepted
30
7368
386
def f(a,x,y): if 0<=x<12 and 0<=y<12 and a[y][x]=='1': a[y][x]='0' for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:f(a,x+dx,y+dy) while 1: try: a=[list(input()) for _ in [0]*12] b=0 for i in range(12): for j in range(12): if a[j][i]=='1': b+=1;f(a,i,j) print(b);input() except:break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,403
s347572725
p00067
u104171359
1487746316
Python
Python3
py
Accepted
20
7760
833
#!usr/bin/env python3 import sys def eliminate_ones(grid, row, col): if 0 <= row < 12 and 0 <= col < 12 and grid[row][col] == 1: grid[row][col] = 0 eliminate_ones(grid, row+1, col) eliminate_ones(grid, row-1, col) eliminate_ones(grid, row, col+1) eliminate_ones(grid, row, col-1) def main(): while True: grid = [[int(num) for num in sys.stdin.readline().strip()] for _ in range(12)] num_of_islands = int() for row in range(len(grid)): for col in range(len(grid[row])): if grid[row][col] == 1: num_of_islands += 1 eliminate_ones(grid, row, col) print(num_of_islands) if not sys.stdin.readline(): break if __name__ == '__main__': main()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,404
s264164022
p00067
u227162786
1490005639
Python
Python3
py
Accepted
30
7728
652
def dfs(i, j, m): ''' m[i][j]??¨????????£??????????????°???????????????????????? ''' m[i][j] = 0 for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni = i + di nj = j + dj if ni in range(12) and nj in range(12) and m[ni][nj] == 1: dfs(ni, nj, m) while True: try: m = [list(map(int, list(input()))) for _ in range(12)] count = 0 for i in range(12): for j in range(12): if m[i][j] == 1: count += 1 dfs(i, j, m) print(count) input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,405
s303849829
p00067
u964040941
1490230595
Python
Python3
py
Accepted
30
7444
704
N = 12 dx = [0,1,0,-1] dy = [-1,0,1,0] def dfs(y,x,vis,S): vis [y] [x] = True for i in range(len(dx)): ny = y + dy [i] nx = x + dx [i] if (ny >= 0 and ny < N and nx >= 0 and nx < N) == False: continue if S [ny] [nx] == '1' and vis [ny] [nx] == False: dfs(ny,nx,vis,S) while True: S = [] for i in range(N): S.append(input()) ans = 0 vis = [[False] * N for i in range(N)] for i in range(N): for j in range(N): if S [i] [j] == '1' and vis [i] [j] == False: dfs(i,j,vis,S) ans += 1 print(ans) try: input() except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,406
s860695270
p00067
u756426560
1490909495
Python
Python3
py
Accepted
30
7732
590
def remove_linked(x, y, DATA): DATA[x][y]=0# clear move = [[1, 0], [0, 1], [-1, 0], [0, -1]]#left, right, down, up for i, j in move: nx,ny=x+i,y+j#next x and y if -1<nx<12 and -1<ny<12 and DATA[nx][ny]: DATA=remove_linked(nx, ny, DATA) return DATA while 1: DATA = [[int(x) for x in list(input())] for _ in range(12)] count = 0 for x in range(12): for y in range(12): if DATA[x][y]: count += 1 DATA = remove_linked(x, y, DATA) print (count) try:input() except:break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,407
s583891416
p00067
u462831976
1493262213
Python
Python3
py
Accepted
30
7492
1,364
# -*- coding: utf-8 -*- import sys import os def solve(island): visited = [] for lst in island: visit_row = [] for c in lst: if c == '1': visit_row.append(False) else: visit_row.append(True) visited.append(visit_row) def paintable(x, y): if 0 <= x < 12 and 0 <= y < 12 and not visited[x][y]: return True else: return False def paint(x, y, number): visited[x][y] = True island[x][y] = number if paintable(x-1, y): paint(x-1, y, number) if paintable(x+1, y): paint(x+1, y, number) if paintable(x, y-1): paint(x, y-1, number) if paintable(x, y+1): paint(x, y+1, number) paint_id = 2 for i in range(12): for j in range(12): if paintable(i, j): paint(i, j, paint_id) paint_id += 1 line = [] for lst in island: line += lst line = set(line) if '0' in lst: line.remove('0') print(len(line)) for s in sys.stdin: s = s.strip() if s != '': island = [list(s)] for i in range(11): s = input().strip() island.append(list(s)) solve(island) else: island = [] pass
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,408
s420995704
p00067
u811733736
1503297465
Python
Python3
py
Accepted
30
7848
3,010
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0067 """ import sys def solve(map): num_of_land = 0 work = [] lmap = map[:] for i in range(1, len(map)): for j in range(1, len(map[0])): if lmap[i][j] == 1: num_of_land += 1 work.append([i, j]) lmap[i][j] = 0 while work: y, x = work.pop() if lmap[y][x+1] == 1: # ???????????? work.append([y, x+1]) lmap[y][x+1] = 0 if lmap[y+1][x] == 1: # ???????????? work.append([y+1, x]) lmap[y+1][x] = 0 if lmap[y][x-1] == 1: # ???????????? work.append([y, x-1]) lmap[y][x-1] = 0 return num_of_land def main(args): data = [ [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0], [0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0], [0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], [0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] ] data = [] buff = [] for line in sys.stdin: line = line.strip() if line: if len(buff) == 0: buff = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] line = '0' + line + '0' buff.append([int(x) for x in line]) else: if len(buff) > 0: buff.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) data.append(buff) buff = [] if len(buff) > 0: buff.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) data.append(buff) buff = [] for map in data: result = solve(map) print(result) if __name__ == '__main__': main(sys.argv[1:])
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,409
s855928469
p00067
u811733736
1503299188
Python
Python3
py
Accepted
40
8064
3,047
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0067 """ import sys import copy def solve(map): num_of_land = 0 work = [] lmap = copy.deepcopy(map) for i, line in enumerate(lmap[1:], start=1): while 1 in line[1:-1]: j = line.index(1) num_of_land += 1 work.append([i, j]) lmap[i][j] = 0 while work: y, x = work.pop() if lmap[y][x+1] == 1: # ???????????? work.append([y, x+1]) lmap[y][x+1] = 0 if lmap[y+1][x] == 1: # ???????????? work.append([y+1, x]) lmap[y+1][x] = 0 if lmap[y][x-1] == 1: # ???????????? work.append([y, x-1]) lmap[y][x-1] = 0 return num_of_land def main(args): # data = [ # [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # [0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], # [0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0], # [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0], # [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], # [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0], # [0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], # [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], # [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], # [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], # [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0], # [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0], # [0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], # # [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # [0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0], # [0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], # [0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], # [0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], # [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], # [0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0], # [0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], # [0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], # [0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] # ] data = [] buff = [] for line in sys.stdin: line = line.strip() if line: if len(buff) == 0: buff = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] line = '0' + line + '0' buff.append([int(x) for x in line]) else: if len(buff) > 0: buff.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) data.append(buff) buff = [] if len(buff) > 0: buff.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) data.append(buff) buff = [] for map in data: result = solve(map) print(result) if __name__ == '__main__': main(sys.argv[1:])
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,410
s569880141
p00067
u510797278
1504496896
Python
Python3
py
Accepted
30
7568
804
import sys dx = [0, 0, -1, 1] dy = [1, -1, 0, 0] def main(): while True: map = [] count = 0 for i in range(12): map.append([x for x in input()]) for i in range(12): for j in range(12): if map[i][j] == '1': dfs(map, j, i) count += 1 print(count) if not sys.stdin.readline(): break def dfs(map, x, y): if x < 0 or y < 0 or x >= 12 or y >= 12: return map[y][x] = '0' for i in range(4): next_x = x + dx[i] next_y = y + dy[i] if next_x >= 0 and next_x < 12 and next_y >= 0 and next_y < 12: if map[next_y][next_x] == '1': dfs(map, next_x, next_y) if __name__ == '__main__': main()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,411
s043558012
p00067
u957021183
1505109957
Python
Python3
py
Accepted
60
7696
3,482
# Aizu Problem 0067: The Number of Islands # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") class UndirectedGraph(): def __init__(self, grid): offsets = [[0, 1], [0, -1], [1, 0], [-1, 0]] N = len(grid) M = len(grid[0]) self.edges = {} self.nodes = [] for row in range(N): for col in range(M): if grid[row][col] == '1': self.AddNode((row, col)) for row_off, col_off in offsets: row2 = row + row_off col2 = col + col_off if 0 <= row2 < N and 0 <= col2 < M and grid[row2][col2] == '1': self.AddEdge((row, col), (row2, col2)) def AddNode(self, node): if node not in self.nodes: self.nodes.append(node) if node not in self.edges: self.edges[node] = [] def GetNodes(self): return self.nodes def GetEdges(self): return self.edges def AddEdge(self, node1, node2): self.AddNode(node1) self.AddNode(node2) if node1 not in self.edges[node2]: self.edges[node2].append(node1) if node2 not in self.edges[node1]: self.edges[node1].append(node2) def Degree(self, node): return len(self.edges[node]) def GetNeighbors(self, node): return self.edges.get(node, []) def GetPath(self, source, target): # find path by BFS: predecessor = {node: -1 for node in self.GetNodes()} predecessor[source] = 0 visited = {node: False for node in self.GetNodes()} queue = [source] while len(queue) > 0: current = queue.pop(0) visited[current] = True for neighbor in self.GetNeighbors(current): if not visited[neighbor] and neighbor not in queue: queue.append(neighbor) predecessor[neighbor] = current if neighbor == target: queue = [] break # build path from predecessor info: if predecessor[target] == -1: return [] path = [target] while path[0] != source: path = [predecessor[path[0]]] + path[:] return path def GetConnectedComponents(self): # identify connected components by BFS nodes = self.GetNodes()[:] connected_components = [] while len(nodes) > 0: queue = [nodes.pop()] component = [queue[0]] while len(queue) > 0: current = queue.pop(0) for neighbor in self.GetNeighbors(current): if neighbor in nodes and neighbor not in queue: queue.append(neighbor) nodes.remove(neighbor) component.append(neighbor) connected_components.append(component) return connected_components finished = False while True: grid = [] if finished: break while True: try: inp = input().strip() except EOFError: finished = True break if len(inp) == 0: break grid.append([_ for _ in inp]) G = UndirectedGraph(grid) print(len(G.GetConnectedComponents()))
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,412
s177125481
p00067
u672443148
1515308984
Python
Python3
py
Accepted
30
5724
714
while True: c=0 islands=[] islandsID=[] ID=0 def dfs(row,col): global ID if 0<=row<12 and 0<=col<12: if islands[row][col]==1 and islandsID[row][col]==0: islandsID[row][col]=ID for dr, dc in [[0,1],[1,0],[0,-1],[-1,0]]: dfs(row+dr,col+dc) for i in range(12): islands.append(list(int(k) for k in input())) for _ in range(12): islandsID.append([0 for i in range(12)]) for i in range(12): for j in range(12): if islands[i][j]==1 and islandsID[i][j]==0: ID+=1 dfs(i,j) print(ID) try: c=input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,413
s738885388
p00067
u024715419
1518506123
Python
Python3
py
Accepted
20
5588
907
def paint(map_inp, x, y): if map_inp[y][x]: map_inp[y][x] = False if map_inp[y][x - 1]: map_inp = paint(map_inp, x - 1, y) if map_inp[y][x + 1]: map_inp = paint(map_inp, x + 1, y) if map_inp[y - 1][x]: map_inp = paint(map_inp, x, y - 1) if map_inp[y + 1][x]: map_inp = paint(map_inp, x, y + 1) return map_inp while True: try: m = [[False for i in range(14)] for j in range(14)] for i in range(12): inp = input() for j in range(12): if inp[j] == "1": m[i + 1][j + 1] = True cnt = 0 for i in range(12): for j in range(12): if m[i + 1][j + 1]: m = paint(m, j + 1, i + 1) cnt += 1 print(cnt) inp = input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,414
s200315613
p00067
u043254318
1518722544
Python
Python3
py
Accepted
20
5624
1,077
def get_input(): while True: try: yield ''.join(input()) except EOFError: break def nuri(table, m, x, y): if table[x-1][y] and m[x-1][y] == 0: m[x-1][y] = m[x][y] nuri(table, m, x-1, y) if table[x+1][y] and m[x+1][y] == 0: m[x+1][y] = m[x][y] nuri(table, m, x+1, y) if table[x][y-1] and m[x][y-1] == 0: m[x][y-1] = m[x][y] nuri(table, m, x, y-1) if table[x][y+1] and m[x][y+1] == 0: m[x][y+1] = m[x][y] nuri(table, m, x, y+1) return N = list(get_input()) for l in range(0,len(N),13): table = [[False for i in range(14)] for j in range(14)] for i in range(12): for j in range(12): if int(N[l+i][j]) == 1: table[i+1][j+1] = True m = [[0 for i in range(14)] for j in range(14)] cnt = 0 for i in range(1,13): for j in range(1,13): if table[i][j] and m[i][j] == 0: cnt += 1 m[i][j] = cnt nuri(table, m, i, j) print(cnt)
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,415
s372930552
p00067
u352394527
1523336766
Python
Python3
py
Accepted
30
5624
793
while True: lst = [] for i in range(12): ls = [] s = input() for j in range(12): ls.append(int(s[j])) lst.append(ls) xd = [0,1,0,-1] yd = [1,0,-1,0] count = 0 def check(pt): if 11 < pt[0] or pt[0] < 0 or 11 < pt[1] or pt[1] < 0: return False elif(lst[pt[0]][pt[1]] == 1): lst[pt[0]][pt[1]] = 0 for i in range(4): check([pt[0]+xd[i],pt[1]+yd[i]]) return True else: return False def printMap(): for i in range(12): st = "" for j in range(12): st = st + str(lst[i][j]) print(st) print() for x in range(12): for y in range(12): if lst[x][y]: check([x,y]) count += 1 #printMap() print(count) try: input() except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,416
s113482097
p00067
u886729200
1523421860
Python
Python3
py
Accepted
20
5576
1,025
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(len(is_data)): for y in range(len(is_data)): if is_data[x][y] == '1':#島が発見されたら dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data) or y<0 or y == len(is_data): return if is_data[x][y] == '1': is_data[x][y] = '0' dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) is_data=[] while True: try: s = list(input())#入力 if not s:#空入力のときループぬける print(counter()) is_data=[] s = [] else: #ls = len(s) is_data.append(s) #for i in range(len(is_data)): #is_data[i] = list(map(int,is_data[i])) #is_data = np.array(is_data).reshape(ls,ls) #print(is_data) except EOFError: print(counter()) break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,417
s229977533
p00067
u886729200
1523422186
Python
Python3
py
Accepted
20
5576
807
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(len(is_data)): for y in range(len(is_data)): if is_data[x][y] == '1':#島が発見されたら dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data) or y<0 or y == len(is_data): return if is_data[x][y] == '1': is_data[x][y] = '0' dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) is_data=[] while True: try: s = list(input())#入力 if not s:#空入力のとき print(counter()) is_data=[] s = [] else: is_data.append(s) except EOFError: print(counter()) break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,418
s442033793
p00067
u352394527
1527543503
Python
Python3
py
Accepted
20
5576
630
direct = ((0, -1), (0, 1), (-1, 0), (1, 0)) #移動方向 def search(x, y, mp): if mp[x][y] == "1": #1を見つけたら0に書き換える mp[x][y] = "0" for dx, dy in direct: #4方向について繰り返す search(x + dx, y + dy, mp) while True: #mp...全体のマップ、上下左右を0で囲っておく mp = [list("0" + input() + "0") for _ in range(12)] mp.insert(0, [0] * 14) mp.append([0] * 14) ans = 0 for x in range(1, 13): for y in range(1, 13): if mp[x][y] == "1": ans += 1 search(x, y, mp) print(ans) try: input() except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,419
s824486759
p00067
u847467233
1529154700
Python
Python3
py
Accepted
30
5608
1,045
# AOJ 0067 The Number of Island # Python3 2018.6.16 bal4u # UNION-FIND library MAX = 12*12 id, size = [0]*MAX, [0]*MAX def init(n): for i in range(n): id[i], size[i] = i, 1 def root(i): while i != id[i]: id[i] = id[id[i]] i = id[i] return i def connected(p, q): return root(p) == root(q) def unite(p, q): i, j = root(p), root(q) if i == j: return if size[i] < size[j]: id[i] = j size[j] += size[i] else: id[j] = i size[i] += size[j] # UNION-FIND library arr = [[0 for r in range(12)] for c in range(12)] dr = [-1, 0, 1, 0] dc = [ 0, 1, 0,-1] while True: init(12*12) for r in range(12): arr[r] = list(map(int, input())) for r in range(12): for c in range(12): if arr[r][c] == 0: continue for i in range(4): nr, nc = r + dr[i], c + dc[i] if nr >= 0 and nr < 12 and nc >= 0 and nc < 12: if arr[nr][nc] == 1: unite(r*12+c, nr*12+nc) ans = 0 for r in range(12): for c in range(12): if arr[r][c] == 1 and root(r*12+c) == r*12+c: ans += 1 print(ans) try: input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,420
s581847963
p00067
u647766105
1356471523
Python
Python
py
Accepted
20
4316
454
def dfs(board,y,x): if not board[y][x]: return 0 board[y][x]=0 dx,dy=[0,1,0,-1],[1,0,-1,0] for i in xrange(4): dfs(board,y+dy[i],x+dx[i]) return 1 while True: try: board=[[0]+map(int,raw_input()[:])+[0] for unused in xrange(12)] board.insert(13,[0]*14) board.insert(0,[0]*14) print sum([dfs(board,i/12+1,i%12+1) for i in xrange(12*12)]) raw_input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,421
s418594836
p00067
u542421762
1371389522
Python
Python
py
Accepted
10
4320
640
import sys def solv(boad): boad = map(lambda x: [0] + x + [0], boad) boad.insert(0, [0] * 14) boad.append([0] * 14) n = sum([foo(boad, x, y) for x in xrange(1, 13) for y in xrange(1, 13)]) return n def foo(b, x, y): if b[y][x]: b[y][x] = 0 foo(b, x-1, y) foo(b, x+1, y) foo(b, x, y-1) foo(b, x, y+1) return 1 else: return 0 boads = [] b = [] for line in sys.stdin: line = line.rstrip() if line == '': boads.append(b) b = [] continue b.append(map(int, line)) boads.append(b) for boad in boads: print solv(boad)
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,422
s971631115
p00067
u782850731
1377600472
Python
Python
py
Accepted
10
4288
926
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin def solve(L): n = 0 sets = set() for y in range(12): for x in range(12): if not L[y][x]: continue elif y and L[y-1][x]: L[y][x] = L[y-1][x] elif x and L[y][x-1]: L[y][x] = L[y][x-1] else: n += 1 sets.add(n) L[y][x] = n for x in range(10, -1, -1): if L[y][x] and L[y][x+1] and L[y][x] != L[y][x+1]: sets.discard(L[y][x]) L[y][x] = L[y][x+1] return len(sets) s = '\n' sep = '\n' while s: L = [] for i in range(12): L.append([int(s) for s in stdin.readline().rstrip()]) print(solve(L)) s = stdin.readline()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,423
s407051546
p00067
u560838141
1379603561
Python
Python
py
Accepted
20
4384
1,953
class UnionFind(object): def __init__(self, size): self.data = [-1 for i in range(size)]; def unite(self, x, y): x = self.root(x); y = self.root(y); if (x != y): if (self.data[y] < self.data[x]): x, y = y, x; self.data[x] += self.data[y]; self.data[y] = x; return x != y; def same(self, x, y): return self.root(x) == self.root(y) def root(self, x): if self.data[x] < 0 : return x; self.data[x] = self.root(self.data[x]); return self.data[x]; def size(self, x): return -self.data[self.root(x)]; def pos(i, j): return i * 14 + j end_flag = False while True: uf = UnionFind(14 * 14); board = []; while True: try: s = raw_input(); except: end_flag = True break s = "0" + s.strip() + "0"; if (s == "00"): break; board.append(list(s)); sent = [0 for i in range(len(board[0]))] board = [sent] + board + [sent]; #print board island = 0 for i in range(1, len(board) - 1): for j in range(1, len(board[0]) - 1): if board[i][j] == '1': p = pos(i, j); f = False; if (board[1 + i][j] == '1'): uf.unite(p, pos(i + 1, j)); f = True; if (board[i - 1][j] == '1'): uf.unite(p, pos(i - 1, j)); f = True; if (board[i][j + 1] == '1'): uf.unite(p, pos(i, j + 1)); f = True; if (board[i][j - 1] == '1'): uf.unite(p, pos(i, j - 1)); f = True; if not f: island += 1 print island + len(filter(lambda x: x < -1, uf.data)); if end_flag: break;
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,424
s264103602
p00067
u912237403
1390096291
Python
Python
py
Accepted
20
4324
905
import sys A=range(12) m=[[0 for i in A] for j in A] def f(y,x): f=0 if m[y][x]==1: m[y][x]=c f=1 return f def LR(y,x,dx): P=[] x+=dx while 0<=x<12 and m[y][x]!=0: if f(y,x):P+=[(y,x)] x+=dx return P def UD(y,x,dy): P=[] y+=dy while 0<=y<12 and m[y][x]!=0: if f(y,x):P+=[(y,x)] y+=dy return P def v1(buf): f=0 while len(buf)>0: f=1 y,x=buf.pop() m[y][x]=c buf+=LR(y,x,-1)+LR(y,x,1)+UD(y,x,-1)+UD(y,x,1) return f def solve(): global c c=2 for i in A: x=m[i] while x.count(1)>0: v1([(i,x.index(1))]) c+=1 return c-2 y=0 for s in sys.stdin: if y<12: x=0 for e in map(int,list(s[:-1])): m[y][x]=e x+=1 y+=1 else: print solve() y=0 print solve()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,425
s619797258
p00067
u912237403
1390097404
Python
Python
py
Accepted
20
4284
703
import sys A=range(12) m=[[0 for i in A] for j in A] def LRUD(y,x,d): P=[] x+=d[0] y+=d[1] if 0<=x<12 and 0<=y<12 and m[y][x]==1: m[y][x]=c P=[(y,x)] return P def v1(buf): while len(buf)>0: y,x=buf.pop() m[y][x]=c for e in [(-1,0),(1,0),(0,-1),(0,1)]: buf+=LRUD(y,x,e) return def solve(): global c c=2 for i in A: x=m[i] while x.count(1)>0: v1([(i,x.index(1))]) c+=1 print c-2 return 0 y=0 for s in sys.stdin: if y<12: x=0 for e in map(int,list(s[:-1])): m[y][x]=e x+=1 y+=1 else: y=solve() solve()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,426
s760017320
p00067
u912237403
1390098548
Python
Python
py
Accepted
20
4280
598
import sys A=range(12) m=[[0 for i in A] for j in A] def f(y,x,d): P=[] x+=d[0] y+=d[1] if 0<=x<12 and 0<=y<12 and m[y][x]==1: m[y][x]=c P=[[y,x]] return P def v1(buf): global c while buf!=[]: y,x=buf.pop() m[y][x]=c for e in [(-1,0),(1,0),(0,-1),(0,1)]:buf+=f(y,x,e) c+=1 return def solve(): global c c=2 for i in A: while m[i].count(1)>0:v1([[i,m[i].index(1)]]) print c-2 return 0 y=0 for s in sys.stdin: if y<12: m[y]=map(int,list(s[:-1])) y+=1 else:y=solve() solve()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,427
s513991938
p00067
u912237403
1390099807
Python
Python
py
Accepted
10
4300
445
import sys A=range(14) m=[[0 for i in A] for j in A] def f(y,x): if m[y][x]==1: m[y][x]=0 f(y,x+1) f(y,x-1) f(y+1,x) f(y-1,x) return def solve(): c=2 for i in A: while m[i].count(1)>0: f(i,m[i].index(1)) c+=1 print c-2 return 0 y=0 for s in sys.stdin: if y<12: m[y+1]=[0]+map(int,list(s[:-1]))+[0] y+=1 else:y=solve() solve()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,428
s924350196
p00067
u912237403
1390100678
Python
Python
py
Accepted
10
4300
415
import sys A=range(14) m=[[0 for i in A]for j in A] def f(y,x): if m[y][x]==1: m[y][x]=0 f(y,x+1) f(y,x-1) f(y+1,x) f(y-1,x) return 1 def solve(): c=0 for i in A: while m[i].count(1)>0:c+=f(i,m[i].index(1)) print c return 0 y=0 for s in sys.stdin: if y<12: y+=1 m[y]=[0]+map(int,list(s[:-1]))+[0] else:y=solve() solve()
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,429
s689042007
p00067
u633068244
1394732431
Python
Python
py
Accepted
20
4336
723
l = 12 def island(f,x,y,m): rf = f[:][:] if rf[y][x] == 1: rf[y][x] = m for i in [-1,1]: if 0 <= x+i <= l-1: rf = island(rf,x+i,y,m) if 0 <= y+i <= l-1: rf = island(rf,x,y+i,m) return rf while True: f = [] m = 2 for i in range(l): f.append(map(int, list(raw_input()))) for y in range(l): for x in range(l): f = island(f,x,y,m) m += 1 ans = [] for i in range(l): for j in range(l): ans.append(f[i][j]) ans = list(set(ans)) if ans.count(0) == 1: print len(ans) - 1 else: print len(ans) try : raw_input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,430
s782303714
p00067
u633068244
1394733583
Python
Python
py
Accepted
20
4340
692
def island(f,x,y,m): rf = f[:][:] rf[y][x] = m for i in [-1,1]: if 0 <= x+i <= 11 and rf[y][x+i] == 1: rf = island(rf,x+i,y,m) if 0 <= y+i <= 11 and rf[y+i][x] == 1: rf = island(rf,x,y+i,m) return rf while True: f = []; m = 2 for i in range(12): f.append(map(int, list(raw_input()))) for y in range(12): for x in range(12): if f[y][x] == 1: f = island(f,x,y,m) m += 1 ans = [] for i in range(12): for j in range(12): ans.append(f[i][j]) ans = list(set(ans)) print len(ans) - 1*ans.count(0) try:raw_input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,431
s118536302
p00067
u260980560
1397985042
Python
Python
py
Accepted
10
4280
850
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1] while True: ans = 0 try: m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14] f = [[False for i in xrange(14)] for j in xrange(14)] for y in xrange(1, 13): for x in xrange(1, 13): if m[y][x]=='1' and f[y][x]==False: q = [[x, y]] f[y][x] = True while len(q)>0: px, py = q.pop(0) for k in xrange(4): nx = px + dx[k]; ny = py + dy[k]; if m[ny][nx]=='1' and f[ny][nx]==False: f[ny][nx] = True q.append([nx, ny]) ans += 1 print ans raw_input() except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,432
s373305269
p00067
u633068244
1399528307
Python
Python
py
Accepted
10
4292
410
W,H = 12,12 dxy = [[1,0],[0,1],[-1,0],[0,-1]] def solve(field,w,h): if 0 <= w < W and 0 <= h < H and field[h][w] == "1": field[h][w] = "0" for dx,dy in dxy: solve(field,w+dx,h+dy) while 1: try: field = [list(raw_input()) for i in range(H)] ans = 0 for h in range(H): for w in range(W): if field[h][w] == "1": solve(field,w,h) ans += 1 print ans raw_input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,433
s877356232
p00067
u708217907
1399817182
Python
Python
py
Accepted
10
4332
631
def get_map(): map = [] while True: try: tmp = list(raw_input()) if len(tmp) != 12: break map.append(tmp) except: break return map def remove_island(x, y, map): map[x][y] = 0 move = [[1, 0], [0, 1], [-1, 0], [0, -1]] for i, j in move: if 0 <= x + i <= 11 and 0 <= y + j <= 11 and map[x + i][y + j] == '1': map = remove_island(x + i, y + j, map) return map[:] while True: map = get_map() if len(map) != 12: break count = 0 for x in range(12): for y in range(12): if map[x][y] == '1': count += 1 map = remove_island(x, y, map) print count
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,434
s564769940
p00067
u491763171
1400481628
Python
Python
py
Accepted
10
4304
605
H, W = 12, 12 dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] def dfs(i, j): field[i][j] = 0 for k in xrange(4): ny = i + dy[k] nx = j + dx[k] if nx < 0 or ny < 0 or nx >= W or ny >= H: continue if field[ny][nx] == 1: dfs(ny, nx) while 1: field = [] for i in xrange(H): field.append(map(int, raw_input())) ret = 0 for i in xrange(H): for j in xrange(W): if field[i][j] == 1: dfs(i, j) ret += 1 print ret try: raw_input() except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,435
s719853437
p00067
u436634575
1402302047
Python
Python3
py
Accepted
40
6728
612
def count_island(ban): def remove(x, y): if 0 <= y < 12 and 0 <= x < 12 and ban[y][x] == 1: ban[y][x] = 0 for dx, dy in [(-1,0), (1,0), (0,-1), (0,1)]: remove(x + dx, y + dy) count = 0 for y in range(12): for x in range(12): if ban[y][x] == 1: count += 1 remove(x, y) print(count) ban = [] while True: try: s = input() except EOFError: break if s: ban.append(list(map(int, s))) else: count_island(ban) ban = [] if ban: count_island(ban)
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,436
s744503109
p00067
u803862921
1571737663
Python
Python3
py
Accepted
30
5616
731
def dfs(L,i,j): if L[i][j] > 0: L[i][j] = 0 else: return for k in [-1, 1]: ni = i + k if ni not in range(12): continue if L[ni][j] > 0: dfs(L, ni, j) for k in [-1, 1]: nj = j + k if nj not in range(12): continue if L[i][nj] > 0: dfs(L, i, nj) return while True: L = [] try: for _ in range(12): L.append( [int(x) for x in input()] ) except: break c = 0 for i in range(12): for j in range(12): if L[i][j] > 0: c += 1 dfs(L, i, j) print(c) try: input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,437
s508537858
p00067
u595265835
1571320979
Python
Python3
py
Accepted
30
5616
574
dx=[1,0,-1,0] dy=[0,1,0,-1] def dfs(i,j,m): m[i][j] = 0 for k in range(4): x = i + dx[k] y = j + dy[k] if (x < 12 and x >= 0 and y < 12 and y >= 0 and m[x][y] == 1): dfs(x,y,m) return while True: try: m = [] sum = 0 for i in range(12): m.append(list(map(int, input()))) for i in range(12): for j in range(12): if (m[i][j] == 1): dfs(i,j,m) sum += 1 print(sum) input() except: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,438
s515573817
p00067
u548252256
1564160551
Python
Python3
py
Accepted
20
5576
505
def dfs(A,x,y): X = [1,0,-1,0] Y = [0,1,0,-1] A[x][y] = 0 for i in range(4): xx = x + X[i] yy = y + Y[i] if 0 <= xx < 12 and 0 <= yy < 12: if A[xx][yy] == "1": dfs(A,xx,yy) if __name__ == '__main__': A = [] while True: try: for _ in range(12): ll = list(input()) A.append(ll) iland = 0 for x in range(12): for y in range(12): if A[x][y] == "1": iland += 1 dfs(A,x,y) print(iland) s = input() A=[] except EOFError: break
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,439
s498501577
p00067
u406093358
1555554094
Python
Python
py
Accepted
10
4692
903
import sys dataset = [] lst = [] for line in sys.stdin: lst.append(line) minilist = [] for i in range(0, len(lst)): if lst[i] == '\n': dataset.append(minilist) minilist = [] else: minilist.append(lst[i]) dataset.append(minilist) for i in range(0, len(dataset)): memo = [] for j in range(0, 12): lst = [] for k in range(0, 12): lst.append(True) memo.append(lst) cnt = 0 for j in range(0, 12): for k in range(0, 12): if dataset[i][j][k] == '1' and memo[j][k]: queue = [[j, k]] while queue != []: now = queue.pop(0) if memo[now[0]][now[1]] and dataset[i][now[0]][now[1]]=='1': memo[now[0]][now[1]] = False for p in range(0, 2): nexth = now[0]-1+2*p nextw = now[1]-1+2*p if 0<=nexth and nexth<12: queue.append([nexth, now[1]]) if 0<=nextw and nextw<12: queue.append([now[0], nextw]) cnt += 1 print cnt
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001
5 13 4
11,440