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
s012644221
p00734
u158979022
1544446792
Python
Python3
py
Accepted
30
5604
353
while True: n, m = map(int, input().split()) if n == 0: break a = [int(input()) for _ in range(n)] b = [int(input()) for _ in range(m)] a.sort b.sort suma = sum(a) sumb = sum(b) def change(): for i in a: for j in b: if(i-j) * 2 == suma - sumb: print(i, j) re...
p00734
<h1><font color="#000000">Problem A:</font> Equal Total Scores</h1> <!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> --> <!-- begin en only --> <p> Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the tot...
2 2 1 5 3 7 6 5 3 9 5 2 3 3 12 2 7 3 5 4 5 10 0 3 8 1 9 6 0 6 7 4 1 1 2 1 2 1 4 2 3 4 3 2 3 1 1 2 2 2 0 0
1 3 3 5 -1 2 2 -1
24,596
s951543481
p00734
u281836941
1513076120
Python
Python3
py
Accepted
40
5600
561
# coding: utf-8 while 1: n,m=map(int,input().split()) if n==0: break taro=[] hana=[] for i in range(n): taro.append(int(input())) for i in range(m): hana.append(int(input())) t_sum=sum(taro) h_sum=sum(hana) d=t_sum-h_sum mn=99999999 ans=[-1] for i ...
p00734
<h1><font color="#000000">Problem A:</font> Equal Total Scores</h1> <!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> --> <!-- begin en only --> <p> Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the tot...
2 2 1 5 3 7 6 5 3 9 5 2 3 3 12 2 7 3 5 4 5 10 0 3 8 1 9 6 0 6 7 4 1 1 2 1 2 1 4 2 3 4 3 2 3 1 1 2 2 2 0 0
1 3 3 5 -1 2 2 -1
24,597
s464118199
p00734
u717727327
1419122825
Python
Python
py
Accepted
20
4228
502
def solve(a, b): a.sort() b.sort() d = sum(a) - sum(b) if d % 2 != 0: return -1 for x in a: for y in b: if x - y == d/2: return " ".join(map(str,[x, y])) if x - y < d/2: break return -1 while True: n, m = map(int, raw_...
p00734
<h1><font color="#000000">Problem A:</font> Equal Total Scores</h1> <!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> --> <!-- begin en only --> <p> Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the tot...
2 2 1 5 3 7 6 5 3 9 5 2 3 3 12 2 7 3 5 4 5 10 0 3 8 1 9 6 0 6 7 4 1 1 2 1 2 1 4 2 3 4 3 2 3 1 1 2 2 2 0 0
1 3 3 5 -1 2 2 -1
24,598
s767054306
p00735
u611579581
1590197059
Python
Python3
py
Accepted
100
6212
804
def prime_factor(N): lists = [N] for i in range(2, int(N ** 0.5) + 1): if N % i == 0: lists.append(i) lists.append(N // i) lists.sort() return lists ans = [] Nlist = [] while True: N = int(input()) if N == 1: break Nlist.append(N) MSprime = []...
p00735
<h1><font color="#000000">Problem B: </font>Monday-Saturday Prime Factors</h1> <!-- end en only --> <p> Chief Judge's log, stardate 48642.5. We have decided to make a problem from elementary number theory. The problem looks like finding all prime factors of a positive integer, but it is not. </p> <!-- end en only -->...
205920 262144 262200 279936 299998 1
205920: 6 8 13 15 20 22 55 99 262144: 8 262200: 6 8 15 20 50 57 69 76 92 190 230 475 575 874 2185 279936: 6 8 27 299998: 299998
24,599
s478573244
p00736
u847467233
1531774479
Python
Python3
py
Accepted
80
5608
933
# AOJ 1155: How can I satisfy thee? Let me count # Python3 2018.7.17 bal4u def term(idx): x, idx = factor(idx) op = buf[idx] y, idx = factor(idx+1); if op == '*': if x == 2 and y == 2: x = 2 elif x == 0 or y == 0: x = 0 else: x = 1 else: if x == 0 and y == 0: x = 0 ...
p00736
<h1><font color="#000000">Problem C:</font> How can I satisfy thee? Let me count the ways...</h1> <!-- end en only --> <!-- begin en only --> <p> Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "t...
(P*Q) (--R+(P*Q)) (P*-P) 2 1 (-1+(((---P+Q)*(--Q+---R))*(-R+-P))) .
3 11 0 27 0 7
24,600
s483233592
p00736
u408260374
1495229200
Python
Python3
py
Accepted
40
7692
972
def parser(left, right): if S[left] == '(' and S[right - 1] == ')': cnt = 0 for i in range(left + 1, right - 1): if S[i] == '(': cnt += 1 elif S[i] == ')': cnt -= 1 elif cnt == 0 and S[i] == '+': return [max(x, y) fo...
p00736
<h1><font color="#000000">Problem C:</font> How can I satisfy thee? Let me count the ways...</h1> <!-- end en only --> <!-- begin en only --> <p> Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "t...
(P*Q) (--R+(P*Q)) (P*-P) 2 1 (-1+(((---P+Q)*(--Q+---R))*(-R+-P))) .
3 11 0 27 0 7
24,601
s886023536
p00736
u856705970
1499080804
Python
Python
py
Accepted
30
6508
1,439
import itertools def parse(expr): if expr == "P": return lambda p, q, r: p if expr == "Q": return lambda p, q, r: q if expr == "R": return lambda p, q, r: r if expr == "0": return lambda p, q, r: 0 if expr == "1": return lambda p, q, r: 1 if expr == "2":...
p00736
<h1><font color="#000000">Problem C:</font> How can I satisfy thee? Let me count the ways...</h1> <!-- end en only --> <!-- begin en only --> <p> Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "t...
(P*Q) (--R+(P*Q)) (P*-P) 2 1 (-1+(((---P+Q)*(--Q+---R))*(-R+-P))) .
3 11 0 27 0 7
24,602
s450085293
p00736
u352394527
1547487557
Python
Python3
py
Accepted
100
5612
1,393
def parse_formula(s, pointer): head = s[pointer] if head == "-": pointer += 1 result, pointer = parse_formula(s, pointer) result = 2 - result elif head == "(": pointer += 1 result_left, pointer = parse_formula(s, pointer) op, pointer = parse_op(s, pointer) ...
p00736
<h1><font color="#000000">Problem C:</font> How can I satisfy thee? Let me count the ways...</h1> <!-- end en only --> <!-- begin en only --> <p> Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "t...
(P*Q) (--R+(P*Q)) (P*-P) 2 1 (-1+(((---P+Q)*(--Q+---R))*(-R+-P))) .
3 11 0 27 0 7
24,603
s149423244
p00741
u886122084
1551441941
Python
Python3
py
Accepted
70
5636
1,194
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline def solve(w, h): mat = [[0]*(w+2) for _ in range(h+2)] for j in range(h): l = list(map(int, input().split())) for i in range(w): mat[j+1][i+1] = l[i] visited = [[False]*(w+2) for _...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,604
s956691440
p00741
u328199937
1555844545
Python
Python3
py
Accepted
80
7920
2,288
import sys sys.setrecursionlimit(10 ** 5) anslist = [] def sarch(i, j, visited): if 0 < i: if visited[i - 1][j] == 0: visited[i - 1][j] = 1 sarch(i - 1, j, visited) if 0 < j: if visited[i - 1][j - 1] == 0: visited[i - 1][j - 1] = 1 ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,605
s340785049
p00741
u617183767
1420388400
Python
Python
py
Accepted
80
5256
1,393
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys import itertools import math from collections import Counter, defaultdict class Main(object): def __init__(self): pass def solve(self): ''' insert your code ''' while True: m, n = map(...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,606
s473417906
p00741
u633068244
1421783769
Python
Python
py
Accepted
60
7648
522
import sys sys.setrecursionlimit(100000) def dfs(x, y): C[y][x] = 0 for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]): if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1: dfs(x+dx, y+dy) while 1: w,h = map(int,raw_input().split()) if w == h == 0: break C = [map...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,607
s819171340
p00741
u731235119
1421922189
Python
Python
py
Accepted
60
5904
1,108
def travel(here, lb, ub, field, label): if field[here[1]][here[0]] == 1: field[here[1]][here[0]] = label if lb[0] < here[0] : travel((here[0]-1, here[1]), lb, ub, field, label) if lb[1] < here[1]: travel((here[0]-1, here[1]-1), lb, ub, field, label) if lb[1] < here[1] : travel((here[0], here[1]-1),...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,608
s534487582
p00741
u120360464
1422868875
Python
Python
py
Accepted
80
4408
1,622
#! /usr/bin/env python # -*- coding: utf-8 -*- def rec(y, x, used, TILE): if (not(0<=x<W)) or (not(0<=y<H)) or (TILE[y][x]==0) or (used[y][x]==1): return 0 else: used[y][x] = 1 rec(y-1, x-1, used, TILE) rec(y-1, x, used, TILE) rec(y-1, x+1, used, TILE) rec(y, x-1...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,609
s163249313
p00741
u966364923
1436629103
Python
Python3
py
Accepted
70
9636
720
import sys def dfs(tiles, W, H, x, y): tiles[y][x] = '0' for dx,dy in ((-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)): if 0<=x+dx<W and 0<=y+dy<H and tiles[y+dy][x+dx]=='1': dfs(tiles, W, H, x+dx, y+dy) return def main(): while True: W,H = [int(x) for x in inp...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,610
s376779162
p00741
u966364923
1436629259
Python
Python3
py
Accepted
60
9636
706
import sys def dfs(tiles, W, H, x, y): tiles[y][x] = '0' for dx,dy in ((-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)): if 0<=x+dx<W and 0<=y+dy<H and tiles[y+dy][x+dx]=='1': dfs(tiles, W, H, x+dx, y+dy) return def main(): while True: W,H = [int(x) for x in inp...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,611
s463360153
p00741
u489809100
1449146503
Python
Python
py
Accepted
40
7868
860
import sys sys.setrecursionlimit(100000) def check(x, y): array[x][y] = "0" if array[x + 1][y] == "1" : check(x + 1, y) if array[x - 1][y] == "1" : check(x - 1, y) if array[x][y + 1] == "1" : check(x, y + 1) if array[x][y - 1] == "1" : check(x, y - 1) if array[x + 1][y + 1] == "1" : check(x + 1, y + 1) if array...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,612
s899414531
p00741
u488601719
1453801170
Python
Python
py
Accepted
70
9920
1,195
import sys sys.setrecursionlimit(100000) vx = [1, -1, 0, 0, 1, 1, -1, -1] vy = [0, 0, 1, -1, 1, -1, 1, -1] def dfs(x, y): c[y][x] = 0 for dx, dy in zip(vx, vy): nx = x + dx ny = y + dy if nx < 0 or ny < 0 or nx >= w or ny >= h: continue if c[ny][nx] == 0: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,613
s974708253
p00741
u488601719
1453801185
Python
Python
py
Accepted
70
9728
675
import sys sys.setrecursionlimit(100000) vx = [1, -1, 0, 0, 1, 1, -1, -1] vy = [0, 0, 1, -1, 1, -1, 1, -1] def dfs(x, y): c[y][x] = 0 for dx, dy in zip(vx, vy): nx = x + dx ny = y + dy if nx < 0 or ny < 0 or nx >= w or ny >= h: continue if c[ny][nx] == 0: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,614
s921336415
p00741
u248416507
1464076991
Python
Python
py
Accepted
80
8460
861
import sys def visit(x, y, area): area[y][x] = 0 move = [(-1, 0), (0, 1), (1, 0), (0, -1), (1, -1), (1, 1), (-1, 1), (-1, -1)] #print '(' + str(x) + ',' + str(y) + ')' for i in move: if 0 <= (x + i[0]) < w and 0 <= (y + i[1]) < h and area[y + i[1]][x + i[0]] == 1: visit(x + i[0], ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,615
s428667039
p00741
u248416507
1464078186
Python
Python
py
Accepted
70
6376
961
def solve_sub(x, y, area): stack = [] stack.append((x, y)) move = [(x, y) for x in range(-1, 2) for y in range(-1, 2) if not (x == 0 and y == 0)] while len(stack) != 0: now = stack.pop() x = now[0] y = now[1] area[y][x] = 0 for dire in move: if 0 <=...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,616
s722048955
p00741
u661290476
1487495441
Python
Python3
py
Accepted
90
9560
629
import sys sys.setrecursionlimit(10**6) def erase(w, h, x, y): c[y][x] = '0' for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)): nx, ny = x + dx, y + dy if 0 <= nx <= w -1 and 0 <= ny <= h - 1: if c[ny][nx] == '1': erase(w, h, nx, ny...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,617
s413701833
p00741
u661290476
1487495602
Python
Python3
py
Accepted
90
9480
611
import sys sys.setrecursionlimit(10**6) def erase(x, y): c[y][x] = '0' for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)): nx, ny = x + dx, y + dy if 0 <= nx <= w -1 and 0 <= ny <= h - 1: if c[ny][nx] == '1': erase(nx, ny) while Tru...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,618
s175815749
p00741
u661290476
1487495738
Python
Python3
py
Accepted
80
9512
586
import sys sys.setrecursionlimit(10**5) def erase(x, y): c[y][x] = '0' for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)): nx, ny = x + dx, y + dy if 0 <= nx < w and 0 <= ny < h and c[ny][nx] == '1': erase(nx, ny) while True: w, h = map(int, in...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,619
s136615538
p00741
u078042885
1487499097
Python
Python3
py
Accepted
100
11824
447
import sys sys.setrecursionlimit(10000) def f(x,y): a[y][x]='0' for dx,dy in[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[1,-1],[-1,1],[1,1]]: dx+=x;dy+=y if 0<=dx<w and 0<=dy<h and a[dy][dx]=='1':f(dx,dy) while 1: w,h=map(int,input().split()) if w==0:break a=[list(input().split()) for _ in[0]...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,620
s691669671
p00741
u078042885
1487500620
Python
Python3
py
Accepted
100
11760
431
import sys sys.setrecursionlimit(10000) def f(x,y): if 0<=x<w and 0<=y<h and a[y][x]=='1': a[y][x]='0' for dx,dy in[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[1,-1],[-1,1],[1,1]]:f(x+dx,y+dy) while 1: w,h=map(int,input().split()) if w==0:break a=[list(input().split()) for _ in[0]*h];b=0 for ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,621
s105006186
p00741
u078042885
1487500761
Python
Python3
py
Accepted
100
11700
425
import sys sys.setrecursionlimit(10000) def f(x,y): if 0<=x<w and 0<=y<h and a[y][x]=='1': a[y][x]='0' for dx,dy in[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[1,-1],[-1,1],[1,1]]:f(x+dx,y+dy) while 1: w,h=map(int,input().split()) if w==0:break a=[input().split() for _ in[0]*h];b=0 for i in r...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,622
s799443665
p00741
u661290476
1487732613
Python
Python3
py
Accepted
90
9556
600
import sys sys.setrecursionlimit(2500) def erase(x, y): c[y][x] = '0' for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)): nx, ny = x + dx, y + dy if 0 <= nx < w and 0 <= ny < h and c[ny][nx] == '1': erase(nx, ny) while True: w, h = map(int, s...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,623
s307928511
p00741
u661290476
1487732685
Python
Python3
py
Accepted
90
9548
587
import sys sys.setrecursionlimit(2500) def erase(x, y): c[y][x] = '0' for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)): nx, ny = x + dx, y + dy if 0 <= nx < w and 0 <= ny < h and c[ny][nx] == '1': erase(nx, ny) while True: w, h = map(int, i...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,624
s181347047
p00741
u661290476
1487732730
Python
Python3
py
Accepted
90
9472
574
import sys sys.setrecursionlimit(2500) def erase(x, y): c[y][x] = '0' for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)): nx, ny = x + dx, y + dy if 0 <= nx < w and 0 <= ny < h and c[ny][nx] == '1': erase(nx, ny) while True: w, h = map(int, i...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,625
s074879162
p00741
u661290476
1487732752
Python
Python3
py
Accepted
90
9596
577
import sys sys.setrecursionlimit(10 ** 5) def erase(x, y): c[y][x] = '0' for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)): nx, ny = x + dx, y + dy if 0 <= nx < w and 0 <= ny < h and c[ny][nx] == '1': erase(nx, ny) while True: w, h = map(int...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,626
s991584598
p00741
u923668099
1495616676
Python
Python3
py
Accepted
80
9440
869
import sys sys.setrecursionlimit(10**5) def solve(): while 1: w, h = map(int, sys.stdin.readline().split()) if w == h == 0: return room = [[int(j) for j in sys.stdin.readline().split()] for i in range(h)] cnt = 0 for i in range(h): for j in range...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,627
s513118033
p00741
u923668099
1495617097
Python
Python3
py
Accepted
100
7924
1,312
import sys from collections import deque sys.setrecursionlimit(10**5) def solve(): while 1: w, h = map(int, sys.stdin.readline().split()) if w == h == 0: return room = [[int(j) for j in sys.stdin.readline().split()] for i in range(h)] cnt = 0 for i in range(...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,628
s298537125
p00741
u510797278
1504843142
Python
Python3
py
Accepted
80
10208
876
import sys dx = [0, 1, 1, 1, 0, -1, -1, -1] dy = [1, 1, 0, -1, -1, -1, 0, 1] w = 0 h = 0 def main(): global w, h while True: count = 0 w, h = map(int, input().split()) if w is 0 and h is 0: break field = [] [field.append(list(map(int, input().split()))) fo...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,629
s905072585
p00741
u811733736
1523068493
Python
Python3
py
Accepted
80
6032
1,248
# -*- coding: utf-8 -*- """ How Many Islands? http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp """ import sys from sys import stdin from collections import deque input = stdin.readline def bfs(data, sx, sy, w, h): dy = [-1, 1, 0, 0, -1, -1, 1, 1] dx = [0, 0, -1, 1, -1, 1, -1, 1] Q = ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,630
s067944850
p00741
u502536402
1524584315
Python
Python3
py
Accepted
80
7928
699
#!python # -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**6) next_s = ((-1, 1), (0, 1), (1, 1), (-1, 0), (1, 0), (-1, -1), (0, -1), (1, -1)) def DFS(x, y): if not (0 <= x < W and 0 <= y < H): return if map_[y][x] == 0: return map_[y][x] = 0 for dx,...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,631
s697958484
p00741
u651355315
1529316247
Python
Python3
py
Accepted
80
9156
713
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10000) def search(n, m, tile, N, M): for dy, dx in zip([-1, -1, -1, 0, 0, 1, 1, 1], [-1, 0, 1, -1, 1, -1, 0, 1]): if 0 <= dy + n < N and 0 <= dx + m < M: if tile[dy + n][dx + m] == '1': tile[dy + n][dx + m] = '2' ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,632
s632874145
p00741
u136916346
1530155019
Python
Python3
py
Accepted
90
7896
1,152
import sys sys.setrecursionlimit(10000) def fill(y,x): global w,h,l if 0<=y<h and 0<=x+1<w and l[y][x+1]==1: l[y][x+1]=0 fill(y,x+1) if 0<=y<h and 0<=x-1<w and l[y][x-1]==1: l[y][x-1]=0 fill(y,x-1) if 0<=y+1<h and 0<=x<w and l[y+1][x]==1: l[y+1][x]=0 fill(...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,633
s529090137
p00741
u109084363
1359533523
Python
Python
py
Accepted
80
4680
1,115
import sys import collections x = [1, 1, 0, -1, -1, -1, 0, 1] y = [0, 1, 1, 1, 0, -1, -1, -1] while True: W, H = map(int, sys.stdin.readline().split()) if W == 0: break tile = [[-1 for i in xrange(W + 2)] for j in xrange(H + 2)] for i in xrange(H): line = raw_input().stri...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,634
s346144926
p00741
u864060739
1597795797
Python
Python3
py
Accepted
90
7972
909
from sys import stdin, setrecursionlimit input = stdin.readline setrecursionlimit(100000) move = ((-1,-1),(-1,0),(-1,1),(0,1),(0,-1),(1,-1),(1,0),(1,1)) def DFS(x,y): if mapmatrix[j][i] == 1 and not checked[y][x]: checked[y][x] = True for dx, dy in move: X = x + dx; Y = y + dy...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,635
s367378743
p00741
u571995157
1597124739
Python
Python3
py
Accepted
90
6020
1,425
from collections import deque from itertools import product import itertools def dfs(w, h, graph): visited = [[0] * w for _ in range(h)] dy_dx = [(0, 0), (0, 1), (0, -1), (1, 1), (1, -1), (1, 0), (-1, 1), (-1, -1), (-1, 0)] dots = itertools.product(range(h), range(w)) count = 0 for dot in dots: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,636
s722029290
p00741
u389047838
1596960661
Python
Python3
py
Accepted
80
6056
1,683
import sys from collections import deque input = sys.stdin.readline def RD(): return input().rstrip() def F(): return float(input().rstrip()) def I(): return int(input().rstrip()) def MI(): return map(int, input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int, input().split())) def ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,637
s490773192
p00741
u512068851
1596954887
Python
Python3
py
Accepted
60
8236
727
import sys sys.setrecursionlimit(5000) dx = [1, 0, -1] dy = [1, 0, -1] def dfs(area, x, y): area[x][y] = 0 for i in dx: for j in dy: next_x = x + i next_y = y + j if area[next_x][next_y] == 1: dfs(area, next_x, next_y) def solver(w, h): ans = 0 ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,638
s186585293
p00741
u432260585
1596492522
Python
Python3
py
Accepted
100
8000
949
import sys sys.setrecursionlimit(10**8) #再帰関数の上限を変更 ans = [] def dfs(x, y): c[x][y] = 0 #今いる場所を0にする for dx in range(-1, 2): for dy in range(-1, 2): nx = x + dx ny = y + dy ##動く先が範囲内で、1であれば移動する if 0 <= nx < h and 0 <= ny < w and c[nx][ny] == 1: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,639
s465280934
p00741
u639414723
1596267245
Python
Python3
py
Accepted
100
6044
1,092
#template def inputlist(): return [int(j) for j in input().split()] #template dx = [1,1,0,-1,-1,-1,0,1] dy = [0,1,1,1,0,-1,-1,-1] from collections import deque def dfs(x,y,w,h,lis,flag): if lis[x][y] == 1: flag = 1 lis[x][y] = 0 stack = deque([]) l = [x,y] stack.appendleft(l)...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,640
s298854161
p00741
u204119336
1596180713
Python
Python3
py
Accepted
90
7988
873
import sys sys.setrecursionlimit(1000000) D = [(1,0), (0,1), (-1,0), (0,-1), (-1,-1),(1,-1),(-1,1),(1,1) ] # 下、右、上、左、斜め def dfs(x,y): # Validation if not(0<=x<H and 0<=y<W) : return # 探索済みか、探索可能かを確認する if f[x][y]!=0 or G[x][y] == 0: return # Validation完了、探索範囲内、探索可能、ゴール以外=>visitフラグを立てる f[x][y]=1 # 次の...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,641
s408040072
p00741
u439569116
1596034353
Python
Python3
py
Accepted
80
8000
623
import sys sys.setrecursionlimit(10**7) def dfs(row, column): Map[row][column] = num for i in range(-1, 2): for j in range(-1, 2): if Map[row + i][column + j] == 1: dfs(row + i, column + j) while True: w, h = map(int, input().split()) if w == h == 0: break ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,642
s546763628
p00741
u258473357
1595847167
Python
Python3
py
Accepted
90
9300
1,136
# coding: utf-8 import sys sys.setrecursionlimit(1000000) class DFSSolver: def __init__(self, table, h, w): self.table = table self.count = 0 self.h = h self.w = w def delta(self, i, j): candididate = [(i-1, j-1), (i-1, j), (i-1, j+1), (i, j-1)...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,643
s703528525
p00741
u836923362
1595607432
Python
Python3
py
Accepted
90
7948
1,063
#00:45 import sys sys.setrecursionlimit(10000000) dx = [1, 0, -1, 0,-1,-1,1,1] dy = [0, 1, 0, -1,-1,1,-1,1] #左上からせめて深さ優先で探索する問題 while True: # 地図作る count = 0 width,hight = map(int,input().split()) if width ==0 : break d =[] for _ in range(hight): d.append(list(map(int,input(...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,644
s070082777
p00741
u847316328
1595568559
Python
Python3
py
Accepted
80
9416
662
import sys sys.setrecursionlimit(2*10**7) def dfs(y,x,h,w): graph[y][x] = 0 for ny,nx in (y+1,x),(y-1,x),(y,x+1),(y,x-1),(y+1,x+1),(y-1,x-1),(y-1,x+1),(y+1,x-1): if not (0<=ny<h and 0<=nx<w) or graph[ny][nx] ==0: continue else: dfs(ny,nx,h,w) return while True: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,645
s635672509
p00741
u525205447
1595481849
Python
Python3
py
Accepted
90
8040
800
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) out = [] while True: W, H = map(int,input().split()) if W == 0 and H == 0: break G = [list(map(int,input().split())) for _ in range(H)] visited = [[False]*W for _ in range(H)] ans = 0 def dfs(h, w): visited[h][w]...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,646
s972528678
p00741
u108855621
1595103985
Python
Python3
py
Accepted
70
8156
830
import sys from itertools import product sys.setrecursionlimit(10 ** 9) def dfs(c, x, y): c[x][y] = 0 for dx, dy in product((-1, 0, 1), repeat=2): if dx == dy == 0: continue if c[x + dx][y + dy] == 1: dfs(c, x + dx, y + dy) def main(): input = sys.stdin.buffer.re...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,647
s285984469
p00741
u819143290
1594962150
Python
Python3
py
Accepted
90
7988
610
#演習2-24 import sys sys.setrecursionlimit(10**6) def dfs(x,y): c[x][y] = 0 for dx in range(-1,2): for dy in range(-1,2): nx = x + dx ny = y + dy if 0 <= nx < h and 0 <= ny < w and c[nx][ny] == "1": dfs(nx,ny) while 1: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,648
s143263160
p00741
u235534975
1594903106
Python
Python3
py
Accepted
90
7992
597
import sys sys.setrecursionlimit(10**6) def dfs(x,y): c[x][y] = 0 for dx in range(-1,2): for dy in range(-1,2): nx = x + dx ny = y + dy if 0 <= nx < h and 0 <= ny < w and c[nx][ny] == "1": dfs(nx,ny) while 1: w,h = m...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,649
s212457958
p00741
u208167569
1594654217
Python
Python3
py
Accepted
80
7932
903
import sys sys.setrecursionlimit(10000) dx = [0, 1, 0, -1, 1, 1, -1, -1] dy = [1, 0, -1, 0, 1, -1, 1, -1] def dfs(field, w, h, height, width): field[height][width] = 0 for i in range(8): nw = width + dx[i] nh = height + dy[i] if nw < 0 or nw >= w or nh < 0 or nh >= h: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,650
s164007694
p00741
u879371540
1594210001
Python
Python3
py
Accepted
100
7996
636
import sys sys.setrecursionlimit(4100000) def dfs(x, y): atlas[y][x] = 0 for horizonal in range(-1, 2): for vertical in range(-1, 2): nx = x + horizonal ny = y + vertical if nx < 0 or w <= nx or ny < 0 or h <= ny: continue if atlas[ny][nx] == 0: continue dfs(nx, ny...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,651
s152747922
p00741
u398903226
1594048244
Python
Python3
py
Accepted
90
8900
2,270
import sys sys.setrecursionlimit(10000) def place(i, j, w): return i*w + j def get_path(w, h, c): path = list() for i in range(h): for j in range(w): # place = i*w + j can_go = list() if c[i][j] != 0: if i != 0 and c[i-1][j] != 0: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,652
s892428512
p00741
u626932242
1593873785
Python
Python3
py
Accepted
80
6052
1,312
import sys from collections import deque sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): ans = [] while True: W, H = map(int, input().split()) if W == H == 0: break grid = [list(map(int, input().split())) for ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,653
s281675939
p00741
u757541954
1593833812
Python
Python3
py
Accepted
90
7988
810
import sys sys.setrecursionlimit(10**6) def dfs(h, w): if visited[h][w]: return 0 elif grid[h][w] == 0: visited[h][w] = True return 0 else: visited[h][w] = True for m in moves: nh, nw = h + m[0], w + m[1] if nh < 0 or nw < 0 or nh >= H or nw ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,654
s307533057
p00741
u357050809
1593767533
Python
Python3
py
Accepted
100
8372
734
import sys sys.setrecursionlimit(10**6) from itertools import product while True: w,h = map(int,input().split()) if w == h == 0: exit() islands = [] for _ in range(h): islands.append(list(map(int,input().split()))) seen = [ [False]*w for _ in range(h) ] def dfs(row,col): seen[row][col] = True ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,655
s859620487
p00741
u842787189
1593703511
Python
Python3
py
Accepted
100
9804
771
import sys sys.setrecursionlimit(10000) def dfs(pos): x = pos[0] y = pos[1] C[y][x] = -1 for x_d, y_d in [[1,0],[1,1],[0,1],[1,-1],[-1,1],[-1,0],[-1,-1],[0,-1]]: x_new = x+x_d y_new = y+y_d if not 0<=x_new<=w-1: continue if not 0<=y_new<=h-1: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,656
s875074440
p00741
u917514663
1593438835
Python
Python3
py
Accepted
70
8728
1,020
import sys sys.setrecursionlimit(10000) def main(): ans=[] while True: w,h=map(int,input().split()) if w==0 and h==0: break dis=[-1,0,1] c=[[0]*(w+2)] for i in range(h): c.append([0]+list(map(int,input().split()))+[0]) c.append([0]*(w+2)) ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,657
s694293144
p00741
u300196536
1593243094
Python
Python3
py
Accepted
100
7988
1,377
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp import sys sys.setrecursionlimit(10000) def dfs(x: int, y: int): """dfsで1つの地続きの島を探索 Parameters ---------- x, y : 探索対称点のxy座標 """ seen[x][y] = True for i in range(8): nx = x + dx[i] ny = y + dy[i] ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,658
s067233999
p00741
u988962397
1593141630
Python
Python3
py
Accepted
80
7980
910
import sys sys.setrecursionlimit(10000) def ironuri(x, y, t, img,h,w): if img[y][x]!=1: return 0 img[y][x]=t if y<h-1: ironuri(x,y+1,t,img,h,w) if y>0: ironuri(x,y-1,t,img,h,w) if x<w-1: ironuri(x+1,y,t,img,h,w) if x>0: ironuri(x-1,y,t,img,h,w) ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,659
s565136053
p00741
u930815300
1593020434
Python
Python3
py
Accepted
90
8608
774
import sys import copy sys.setrecursionlimit(10**7) dx = [1,0,-1,0,1,1,-1,-1] dy = [0,1,0,-1,1,-1,1,-1] def dfs(MAP,w,h,x,y): MAP[y][x] = 0 for dir in range(8): nx = x + dx[dir] ny = y + dy[dir] if nx < 0 or nx >= w or ny < 0 or ny >= h: continue if MAP[ny][nx] == 0: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,660
s423617622
p00741
u057134693
1592842604
Python
Python3
py
Accepted
100
8028
846
# 25 import sys import itertools sys.setrecursionlimit(10**7) #再帰関数の呼び出し制限 while True: w, h = map(int, input().split()) if w == 0 and h == 0: break c_l = [[int(x) for x in input().split()] for y in range(h)] s_l = [[True] * w for x in range(h)] v_l = list(itertools.product([-1,0,1],repeat=...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,661
s196918810
p00741
u420455834
1592730935
Python
Python3
py
Accepted
90
8816
1,253
import sys import itertools # import numpy as np import time import math sys.setrecursionlimit(10 ** 7) from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines while True: W, H = map(int, input().split()) if W == 0 and H...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,662
s541076208
p00741
u272080389
1592707628
Python
Python3
py
Accepted
100
5720
847
#「探索候補スタック」「探索済みリスト」「現在地点」の3点セットでとらえる while 1: w,h=map(int,input().split()) if w==h==0: break c=[list(map(int,input().split())) for _ in range(h)] dxdy=[[1,0],[-1,0],[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]] ans=0 for y in range(h): for x in range(w): if c[y][x]: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,663
s212800309
p00741
u040807768
1592702348
Python
Python3
py
Accepted
100
8476
786
import sys sys.setrecursionlimit(10**7) def dfs_rec(): W,H = list(map(int,input().split())) if W == 0 and H == 0: exit() C = [list(map(int,input().split())) for _ in range(H)] D = [[0,1],[0,-1],[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1]] def dfs(C, x, y): C[y][x] = 2 for d...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,664
s498083595
p00741
u017035192
1592681376
Python
Python3
py
Accepted
90
8624
630
import sys sys.setrecursionlimit(10 ** 7) def dfs(y, x): if not (0 <= y < h) or not (0 <= x < w) or not L[y][x]: return else: L[y][x] = 0 dy = [1, 1, 1, 0, 0, -1, -1, -1] dx = [-1, 0, 1, -1, 1, -1, 0, 1] for i in range(8): ny = y + dy[i] nx = x + dx[i] ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,665
s613007276
p00741
u370865645
1592664722
Python
Python3
py
Accepted
90
7956
971
import sys sys.setrecursionlimit(50*50) seen = [] field = [] dx =[0, 1, 1, 1, 0, -1, -1, -1] dy =[1, 1, 0, -1, -1, -1, 0, 1] global W, H def dfs_grid(w, h): seen[h][w]=True #print(h, w) for i in range(8): nw = w + dx[i] nh = h + dy[i] if nw < 0 or nw >= W or nh < 0 or nh >= H: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,666
s038483792
p00741
u356287728
1592545069
Python
Python3
py
Accepted
70
7892
814
import sys sys.setrecursionlimit(10**7) while(True): # w, h <= 50 w, h = map(int, input().split()) if w == 0 and h == 0: break # 0=>海, 1=>陸 island = [list(input().split()) for _ in range(h)] island_number = 0 def dfs(y, x): if x < 0 or w <= x or y < 0 or h <= y: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,667
s555560758
p00741
u476858890
1591896022
Python
Python3
py
Accepted
100
7044
802
from sys import setrecursionlimit setrecursionlimit(10 ** 9) dir_h = [1, -1, 0, 0, 1, -1, -1, 1] dir_w = [1, -1, 1, -1, 0, 0, 1, -1] def dfs(i, j): if i < 0 or i >= h or j < 0 or j >= w: return if field[i][j] == 0 or seen[i][j] != 0: return seen[i][j] = 1 for dh, dw in zip(dir_h,...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,668
s553783073
p00741
u156732351
1591627163
Python
Python3
py
Accepted
90
8024
709
import sys sys.setrecursionlimit(10**6) def dfs(i, j): # i行j列の島を探索する seen[i][j] = 1 for k in range(i-1, i+2): for l in range(j-1, j+2): if k < 0 or k >= h or l < 0 or l >= w: continue if seen[k][l]: continue if c[k][l] == 0: continue dfs(k, l) while T...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,669
s299768506
p00741
u798363880
1591602726
Python
Python3
py
Accepted
80
7916
1,291
import sys sys.setrecursionlimit(20000) w,h=list(map(int,input().split())) def simaserach(i,j): if color[i][j]=="w": color[i][j]="g" if i>=1: if sima[i-1][j]==1: simaserach(i-1,j) if j>=1: if sima[i-1][j-1]==1: simaserach(i-...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,670
s369515966
p00741
u777962369
1591370284
Python
Python3
py
Accepted
70
8048
874
import sys sys.setrecursionlimit(10**8) def dfs(h,w,visited,S): #print(h,w) for i in range(8): h0 = h+dh[i] w0 = w+dw[i] if visited[h0][w0]==False and S[h0][w0]=='1': visited[h0][w0]=True dfs(h0,w0,visited,S) ans = [] while True: W,H = map(int, input().split...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,671
s082132756
p00741
u174781513
1591195173
Python
Python3
py
Accepted
80
9824
426
import sys sys.setrecursionlimit(10000) def f(x,y): if 0<=x<w and 0<=y<h and a[y][x]=='1': a[y][x]='0' for dx,dy in[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[1,-1],[-1,1],[1,1]]:f(x+dx,y+dy) while 1: w,h=map(int,input().split()) if w==0:break a=[input().split() for _ in[0]*h];b=0 for i in r...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,672
s006776399
p00741
u845612949
1590810154
Python
Python3
py
Accepted
60
7988
929
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) count_list = [] while True: w, h = map(int, input().split()) if (w, h) == (0, 0): break grid = [0] * (w + 2) for _ in range(h): grid += [0] grid += list(map(int, input().split())) grid += [0]...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,673
s599556866
p00741
u781213648
1590722787
Python
Python3
py
Accepted
100
5624
1,027
# 深さ優先探索 def dfs(sy, sx, visited, C): cango = [[1, 1], [1, 0], [1, -1], [0, 1], [0, -1], [-1, 1], [-1, 0], [-1, -1]] stack = [[sy, sx]] if visited[sy][sx] == 1:#きたことあるならスルー return 0 visited[sy][sx] = 1 if C[sy][sx] == 0:#もし海ならスルー return 0 while stack: y, x = stack[-1] st...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,674
s203568666
p00741
u356546564
1590596632
Python
Python3
py
Accepted
70
8740
959
import sys sys.setrecursionlimit(2500) def dfs(i, j): global visited visited[i][j] = True for ii in [i - 1, i, i + 1]: for jj in [j - 1, j, j + 1]: if c[ii][jj] and not visited[ii][jj]: dfs(ii, jj) w_list = [] h_list = [] c_list = [] while True: w, h = [int(x) for x ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,675
s453033674
p00741
u430457144
1590575831
Python
Python3
py
Accepted
100
8368
712
import sys from itertools import product sys.setrecursionlimit(10000) while True: W, H = map(int, input().split(' ')) if W == 0 and H == 0: break m = tuple([list(map(int, input().split(' '))) for _ in range(H)]) def dfs(y, x): if m[y][x] == 0: return False else: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,676
s311513664
p00741
u061207034
1590566637
Python
Python3
py
Accepted
100
8156
762
import sys def dfs(M, i, j, h, w): M[i][j] = 0 for dy in range(-1, 2): for dx in range(-1, 2): ny, nx = i+dy, j+dx if 0 <= ny < h and 0 <= nx < w and M[ny][nx] == 1: dfs(M, ny, nx, h, w) def search(M, w, h): count = 0 for i in range(h): for j i...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,677
s625931879
p00741
u069607647
1590334081
Python
Python3
py
Accepted
70
5632
1,290
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp import sys read = sys.stdin.read readline = sys.stdin.readline def main(): ans = [] while True: w, h = map(int, readline().split()) if w == 0: break c = [[0] * (w+2)] for _ in range(h): ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,678
s980671477
p00741
u083560545
1590075233
Python
Python3
py
Accepted
100
5628
672
import sys sys.setrecursionlimit(10**7) def dfs(sx,sy): stack=[[sx,sy]] while(stack): x,y=stack.pop() move=[[x,y],[x,y-1],[x,y+1],[x+1,y],[x-1,y],[x-1,y-1],[x+1,y+1],[x+1,y-1],[x-1,y+1]] for mx,my in move: if not(0<=mx<=h-1) or not(0<=my<=w-1): continue elif l[mx][my]==1: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,679
s472991846
p00741
u789716290
1589983209
Python
Python3
py
Accepted
100
6284
1,041
from collections import deque def main(H,W): area = [[] for i in range(H)] island = [] for _ in range(H): h = list(map(int,input().split())) area[_] = h for i in range(W): if h[i] == 1: island.append([_,i]) visited = [[0] * W for i in range(H)] def dfs(area, visited,sh,sw):...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,680
s557398426
p00741
u256637043
1589810532
Python
Python3
py
Accepted
100
8332
1,133
# aoj_how_meny_island.py import sys sys.setrecursionlimit(500000) def printseen(): for i in seen: print(i) def dsf(h,w): seen[h][w]=True for i in dh: for j in dw: nh = h+i nw = w+j if canGo(nh,nw,i,j): dsf(nh,nw) return 1 def canGo(nh...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,681
s282767653
p00741
u286314212
1589682524
Python
Python3
py
Accepted
100
6036
857
import collections,itertools,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) while 1: w,h = LI() if w==h==0: break ans = 0 c = [LI() for _ in range(h)] seen = [[0]*w for _ in range(h)] stack = [] dhdw = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,682
s508155280
p00741
u153034461
1589610766
Python
Python3
py
Accepted
100
8484
776
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy def dfs(y,x): if x<0 or x>=w or y<0 or y>=h: return if li[y][x] == 0: return if li[y][x] == 1: li[y][x] = 0 dfs(y,x+1) ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,683
s211916570
p00741
u502283627
1589547376
Python
Python3
py
Accepted
100
7604
1,141
import sys sys.setrecursionlimit(3000) while True: w, h = map(int, input().split()) if w == 0 and h == 0: exit() C = [] for i in range(h): c = list(map(int, input().split())) C.append(c) def is_island(i, j): if 0 <= i < h and 0 <= j < w and C[i][j] == 1: ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,684
s004766899
p00741
u414989419
1589512576
Python
Python3
py
Accepted
100
7984
854
import sys sys.setrecursionlimit(10**6) # 移動ベクトル dx = [1, 1, 0, -1, -1, -1, 0, 1] dy = [0, 1, 1, 1, 0, -1, -1, -1] def dfs(h, w): seen[h][w] = True # 次の探索位置を取得 for dir in range(8): nh, nw = h + dx[dir], w + dy[dir] if nh < 0 or nh >= H or nw < 0 or nw >= W: continue if field[n...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,685
s878208983
p00741
u428671978
1589282338
Python
Python3
py
Accepted
80
7876
645
from sys import stdin from sys import setrecursionlimit setrecursionlimit(10**9) def dfs(y,x): for dy,dx in (-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1),(1,-1),(1,1): ny,nx=y+dy,x+dx if 0<=ny<h and 0<=nx<w: if grid[ny][nx]==1: grid[ny][nx]=0 dfs(ny,nx) while...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,686
s850897539
p00741
u737337423
1588672738
Python
Python3
py
Accepted
90
5668
1,378
import sys class UnionFind: def __init__(self, n=0): self.d = [-1]*n self.u = n def root(self, x): if self.d[x] < 0: return x self.d[x] = self.root(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.root(x), self.root(y) if ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,687
s223687763
p00741
u330854367
1588628002
Python
Python3
py
Accepted
90
6044
858
import collections,itertools,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) while 1: w,h = LI() if w==h==0: break ans = 0 c = [LI() for _ in range(h)] seen = [[0]*w for _ in range(h)] stack = [] dhdw = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,688
s600422634
p00741
u596318921
1588583959
Python
Python3
py
Accepted
80
7840
852
import sys sys.setrecursionlimit(10**7) vec = [(1,0),(0,1),(-1,0),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)] def dfs(x,y,visited,field): visited[x][y] = 1 for nx,ny in vec: tx = x + nx ty = y+ny if tx < 0 or ty < 0 or tx > h-1 or ty > w-1:continue ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,689
s380048600
p00741
u490760133
1588478184
Python
Python3
py
Accepted
100
7992
621
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) def dfs(h, w): board[h][w] = 0 for dh in range(-1, 2): for dw in range(-1, 2): nh = h + dh nw = w + dw if 0 <= nh < H and 0 <= nw < W and board[nh][nw] == 1: dfs(nh, nw) while Tru...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,690
s142393403
p00741
u157179698
1588414793
Python
Python3
py
Accepted
70
7632
1,367
import sys input=sys.stdin.readline sys.setrecursionlimit(10 ** 6) #from collections import defaultdict #d = defaultdict(int) #import fractions #import math #import collections #from collections import deque #from bisect import bisect_left #from bisect import insort_left #N = int(input()) #A = list(map(int,input().spli...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,691
s948100461
p00741
u961800354
1588413939
Python
Python3
py
Accepted
60
7924
1,131
import sys sys.setrecursionlimit(1000000) def dfs(h, w, field, seen, dhw): seen[h][w] = True for dh, dw in dhw: nh = h + dh nw = w + dw if field[nh][nw] == 0: continue if seen[nh][nw]: continue dfs(nh, nw, field, seen, dhw) def main(): re...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,692
s284769914
p00741
u772853944
1588406512
Python
Python3
py
Accepted
100
5640
1,190
# coding: utf-8 import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces def main(): w,h = na() if w==0 and h==0: return 0 field = [na() for _ in range(h)] checked = [[0 for _ ...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,693
s950202826
p00741
u555063680
1588336813
Python
Python3
py
Accepted
80
7924
686
import sys sys.setrecursionlimit(10**9) H = 0 W = 0 field = [] def dfs(x, y, px, py): for dx, dy in ((1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,1),(1,-1),(-1,-1)): dx += x dy += y if dx == px and dy == py: continue if not (0 <= dx < W and 0 <= dy < H): continue if field[dy][dx] == 1...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,694
s688550400
p00741
u867685455
1588204172
Python
Python3
py
Accepted
90
8100
791
import sys sys.setrecursionlimit(20000) def fill(m, h, w, x, y): m[y][x] = 0 for i in range(-1, 2): for j in range(-1, 2): nx = x + i ny = y + j if nx < 0 or nx >= w or ny < 0 or ny >= h: continue if m[ny][nx] == 0: contin...
p00741
<h1><font color="#000000">Problem B:</font> How Many Islands?</h1> <p> You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009B2"><br> Figure B-1...
1 1 0 2 2 0 1 1 0 3 2 1 1 1 1 1 1 5 4 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 5 4 1 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 1 5 5 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0
0 1 1 3 1 9
24,695