結果

問題 No.401 数字の渦巻き
ユーザー osada-yumosada-yum
提出日時 2023-10-30 16:52:43
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 33,568 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-30 16:52:49
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program yukicoder_401
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(int32) :: n, y, x, next_y, next_x, direction
  integer(int32), allocatable :: grids(:, :)
  integer(int32) :: i
  read(input_unit, *) n
  allocate(grids(0:n+1, 0:n+1), source = -1)
  grids(0, :) = huge(0_int32)
  grids(:, 0) = huge(0_int32)
  grids(n + 1, :) = huge(0_int32)
  grids(:, n + 1) = huge(0_int32)
  y = 1; x = 1
  direction = 1
  do i = 1, n * n
     grids(y, x) = i
     ! write(error_unit, *) grids(1:n, 1:n)
     select case(direction)
     case(1) !> EAST.
        if (grids(y, x + 1) > 0) then
           direction = 2
           y = y + 1
        else
           x = x + 1
        end if
     case(2) !> SOUTH.
        if (grids(y + 1, x) > 0) then
           direction = 3
           x = x - 1
        else
           y = y + 1
        end if
     case(3) !> WEST.
        if (grids(y, x - 1) > 0) then
           direction = 4
           y = y - 1
        else
           x = x - 1
        end if
     case(4) !> NORTH.
        if (grids(y - 1, x) > 0) then
           direction = 1
           x = x + 1
        else
           y = y - 1
        end if
     end select
  end do
  do i = 1, n
     write(output_unit, '(*(i3.3, 1x))') grids(i, 1:n)
  end do
end program yukicoder_401
0