結果
問題 |
No.401 数字の渦巻き
|
ユーザー |
|
提出日時 | 2023-10-30 16:52:43 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,286 bytes |
コンパイル時間 | 664 ms |
コンパイル使用メモリ | 33,892 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-25 17:19:20 |
合計ジャッジ時間 | 1,656 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
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