結果

問題 No.515 典型LCP
ユーザー jjjj
提出日時 2017-05-05 23:54:32
言語 Fortran
(gFortran 13.2.0)
結果
RE  
実行時間 -
コード長 1,575 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 28,788 KB
実行使用メモリ 5,276 KB
最終ジャッジ日時 2023-10-12 10:36:02
合計ジャッジ時間 7,848 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.f90:69:30:

     write(cformat(5:9),'(i0)'),size(array)
                              1
Warning: Legacy Extension: Comma before i/o item list at (1)

ソースコード

diff #

program main
  implicit none
  integer*8::N
  character*800000,allocatable::S(:)
  integer*8,allocatable::i(:),j(:)
  integer*4,allocatable::ij(:,:)
  integer*8::k,M,x,d,summ
  read *,N
  allocate(S(N))
  do k=1,N
     read *,S(k)
  end do
  allocate(i(N),j(N))
  read *, M, x, d
  allocate(ij(N,N))
  ij=-1
  call query(N,M,x,d,i,j)

  summ = 0
  do k=1,M
     summ = summ + get_lcp(S,i(k),j(k),ij)
  end do
  print '(i0)',summ
contains
  integer*8 function get_lcp(S,ik,jk,ij) result(lcp)
    character*800000,allocatable,intent(in)::S(:)
    integer*4,allocatable::ij(:,:)
    integer*8::ik,jk
    integer*8::silen,sjlen,ii

    if(ij(ik,jk).ne.-1) then
       lcp = ij(ik,jk)
       return
    end if

    lcp = 0
    do ii=1,MIN(LEN_TRIM(S(ik)),LEN_TRIM(S(jk)))
       if(S(ik)(ii:ii).eq.S(jk)(ii:ii)) then
          lcp = lcp + 1
       else
          exit
       end if
    end do
    ij(ik,jk) = lcp
  end function get_lcp

  subroutine query(N,M,x,d,i,j)
    integer*8::tmp,k
    integer*8,intent(in)::M,d,N
    integer*8,intent(inout)::x
    integer*8,allocatable::i(:),j(:)

    do k=1, M
       i(k) = (x/(N-1))+1
       j(k) = MOD(x,(N-1))+1
       if(i(k).gt.j(k)) then
          tmp = j(k)
          j(k) = i(k)
          i(k) = tmp
       else
          j(k) = j(k) + 1
       end if
       x = MOD((x+d),N*(N-1))
    end do
  end subroutine query
  subroutine aprinter(array)
    integer*8::array(:)
    character*32::cformat='(i0,     (1x,i0))'
    write(cformat(5:9),'(i0)'),size(array)
    write(*,cformat) array
  end subroutine aprinter
end program main
0