結果
問題 | No.2946 Puyo |
ユーザー | osada-yum |
提出日時 | 2024-11-13 00:37:04 |
言語 | Fortran (gFortran 13.2.0) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 2,465 bytes |
コンパイル時間 | 1,685 ms |
コンパイル使用メモリ | 34,560 KB |
実行使用メモリ | 29,824 KB |
最終ジャッジ日時 | 2024-11-13 00:37:13 |
合計ジャッジ時間 | 7,896 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 136 ms
7,300 KB |
testcase_04 | AC | 136 ms
7,156 KB |
testcase_05 | AC | 137 ms
7,168 KB |
testcase_06 | AC | 140 ms
7,236 KB |
testcase_07 | AC | 134 ms
7,152 KB |
testcase_08 | AC | 11 ms
6,820 KB |
testcase_09 | AC | 46 ms
6,820 KB |
testcase_10 | AC | 10 ms
6,820 KB |
testcase_11 | AC | 71 ms
6,816 KB |
testcase_12 | AC | 10 ms
6,820 KB |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 16 ms
6,820 KB |
testcase_15 | AC | 8 ms
6,820 KB |
testcase_16 | AC | 24 ms
6,820 KB |
testcase_17 | AC | 78 ms
6,820 KB |
testcase_18 | AC | 3 ms
6,820 KB |
testcase_19 | AC | 36 ms
6,816 KB |
testcase_20 | AC | 47 ms
6,816 KB |
testcase_21 | AC | 77 ms
6,820 KB |
testcase_22 | AC | 11 ms
6,816 KB |
testcase_23 | AC | 47 ms
6,816 KB |
testcase_24 | AC | 110 ms
6,820 KB |
testcase_25 | AC | 95 ms
6,816 KB |
testcase_26 | AC | 106 ms
6,820 KB |
testcase_27 | AC | 3 ms
6,820 KB |
testcase_28 | AC | 85 ms
11,648 KB |
testcase_29 | AC | 116 ms
12,160 KB |
testcase_30 | AC | 65 ms
10,496 KB |
testcase_31 | AC | 96 ms
13,056 KB |
testcase_32 | AC | 92 ms
7,680 KB |
testcase_33 | AC | 78 ms
6,820 KB |
testcase_34 | AC | 113 ms
8,192 KB |
testcase_35 | AC | 95 ms
6,816 KB |
testcase_36 | AC | 97 ms
6,912 KB |
testcase_37 | AC | 102 ms
6,816 KB |
testcase_38 | AC | 73 ms
6,816 KB |
testcase_39 | AC | 70 ms
6,816 KB |
testcase_40 | AC | 44 ms
6,816 KB |
testcase_41 | AC | 93 ms
6,816 KB |
testcase_42 | AC | 85 ms
6,820 KB |
testcase_43 | AC | 94 ms
24,064 KB |
testcase_44 | AC | 115 ms
29,824 KB |
testcase_45 | AC | 85 ms
14,464 KB |
testcase_46 | AC | 51 ms
6,912 KB |
testcase_47 | AC | 77 ms
10,240 KB |
ソースコード
!> This file was processed by `fypp`. !> Today's fortune: "forever WJ...", really OK? !> ランダムウォーク猿「'半分全列挙' で はっぴー.」 program f902946 use, intrinsic :: iso_fortran_env !> auto use module implicit none integer(int32), parameter :: dy(*) = [1, 0, -1, 0] integer(int32), parameter :: dx(*) = [0, 1, 0, -1] integer(int32) :: h, w character, allocatable :: grids(:, :) logical, allocatable :: visited(:, :) integer(int32) :: i, j read(input_unit, *) h, w allocate(grids(h, w)) do i = 1, h read(input_unit, '(*(a1))') grids(i, :) end do allocate(visited(h, w), source = .false.) do j = 1, w do i = 1, h if (visited(i, j)) cycle if (grids(i, j) == ".") cycle ! write(error_unit, *) j, i, grids(i, j) block integer(int32) :: cnts character :: first_c cnts = 0 call dfs_count(h, w, grids, visited, cnts, i, j) if (cnts < 4) cycle first_c = grids(i, j) call dfs_fill(h, w, first_c, grids, i, j) end block end do end do do i = 1, h write(output_unit, '(*(a1))') grids(i, :) end do contains pure recursive subroutine dfs_count(h, w, grids, visited, cnts, y, x) integer(int32), intent(in) :: h, w character, intent(in) :: grids(h, w) logical, intent(inout) :: visited(h, w) integer(int32), intent(inout) :: cnts integer(int32), intent(in) :: y, x integer(int32) :: d if (visited(y, x)) return visited(y, x) = .true. cnts = cnts + 1 do d = 1, size(dy) associate(ny => y + dy(d), nx => x + dx(d)) if (ny < 1 .or. ny > h .or. nx < 1 .or. nx > w) cycle if (visited(ny, nx)) cycle if (grids(y, x) /= grids(ny, nx)) cycle call dfs_count(h, w, grids, visited, cnts, ny, nx) end associate end do end subroutine dfs_count pure recursive subroutine dfs_fill(h, w, c, grids, y, x) integer(int32), intent(in) :: h, w character, intent(in) :: c character, intent(inout) :: grids(h, w) integer(int32), intent(in) :: y, x integer(int32) :: d grids(y, x) = "." do d = 1, size(dy) associate(ny => y + dy(d), nx => x + dx(d)) if (ny < 1 .or. ny > h .or. nx < 1 .or. nx > w) cycle if (c /= grids(ny, nx)) cycle call dfs_fill(h, w, c, grids, ny, nx) end associate end do end subroutine dfs_fill end program f902946