結果
| 問題 |
No.515 典型LCP
|
| ユーザー |
jj
|
| 提出日時 | 2017-05-05 23:54:32 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,575 bytes |
| コンパイル時間 | 1,763 ms |
| コンパイル使用メモリ | 33,652 KB |
| 実行使用メモリ | 14,016 KB |
| 最終ジャッジ日時 | 2024-09-14 09:28:03 |
| 合計ジャッジ時間 | 4,841 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | RE * 2 TLE * 1 -- * 12 |
コンパイルメッセージ
Main.f90:69:30:
69 | write(cformat(5:9),'(i0)'),size(array)
| 1
Warning: Legacy Extension: Comma before i/o item list at (1)
ソースコード
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
jj