結果
| 問題 |
No.52 よくある文字列の問題
|
| コンテスト | |
| ユーザー |
jj
|
| 提出日時 | 2017-01-28 23:33:35 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,255 bytes |
| コンパイル時間 | 1,625 ms |
| コンパイル使用メモリ | 36,052 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 05:28:08 |
| 合計ジャッジ時間 | 2,214 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 |
ソースコード
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
jj