結果

問題 No.52 よくある文字列の問題
ユーザー jjjj
提出日時 2017-01-28 23:33:35
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,255 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 35,892 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:06:20
合計ジャッジ時間 2,291 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  character*10::S
  character::c
  integer::a(26),ca
  integer::num(10)
  integer::pat(1024),spat(1024)
  integer::len,i,j,k
  integer::N
  integer,allocatable::x(:),y(:)
  data a/26*0/,num/10*0/

  read *,S
  len = LEN_TRIM(S)
  N = 0
  ca = ICHAR('a')
  do i=0,25
     c = CHAR(ca+i)
     if(SCAN(S,c).eq.0) cycle
     do j=1,len
        if(S(j:j).eq.c)  num(j) = N
     end do
     N = N + 1
  end do

  allocate(x(2**len),y(2**len))

  do i=1,2**len
     k = 0
     x(i) = 0
     do j=0,len-1
        if(btest(i,j).eqv..true.) then
           k = k + 1
           x(i) = x(i) + num(k)*10**j
        else
           x(i) = x(i) + num(len-(j-k))*10**j
        end if
     end do
  end do
  y = qsort(x)

  j = 1
  do i = 1,2**len-1
     if(y(i).ne.y(i+1)) then
        j = j + 1
     end if
  end do
  print '(i0)', j

contains
  recursive function qsort(x) result(y)
    integer,intent(in) ::x(:)
    integer,allocatable::y(:)
    integer::pivot,total
    total = size(x)
    if (total <=1) then
       y = x
    else
       pivot = x(total/2)
       y = [qsort(pack(x, x .lt. pivot)), &
            pack(x, x .eq. pivot),        &
            qsort(pack(x, x .gt. pivot))]
    endif
  end function qsort

end program main
0