結果

問題 No.355 数当てゲーム(2)
ユーザー jjjj
提出日時 2017-01-08 07:30:26
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,815 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 29,836 KB
実行使用メモリ 24,348 KB
平均クエリ数 24.96
最終ジャッジ日時 2023-09-24 00:49:40
合計ジャッジ時間 5,070 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,532 KB
testcase_01 AC 24 ms
23,364 KB
testcase_02 AC 19 ms
23,628 KB
testcase_03 AC 22 ms
23,676 KB
testcase_04 AC 20 ms
23,388 KB
testcase_05 AC 21 ms
23,364 KB
testcase_06 AC 21 ms
23,520 KB
testcase_07 AC 20 ms
23,388 KB
testcase_08 AC 20 ms
23,652 KB
testcase_09 AC 20 ms
23,796 KB
testcase_10 AC 20 ms
23,796 KB
testcase_11 AC 19 ms
24,048 KB
testcase_12 AC 20 ms
23,820 KB
testcase_13 AC 21 ms
23,364 KB
testcase_14 AC 20 ms
24,336 KB
testcase_15 AC 21 ms
24,012 KB
testcase_16 AC 21 ms
24,288 KB
testcase_17 AC 20 ms
24,228 KB
testcase_18 AC 18 ms
23,652 KB
testcase_19 AC 21 ms
23,388 KB
testcase_20 AC 20 ms
24,312 KB
testcase_21 AC 21 ms
23,628 KB
testcase_22 AC 20 ms
23,808 KB
testcase_23 AC 20 ms
24,240 KB
testcase_24 AC 21 ms
23,376 KB
testcase_25 AC 21 ms
23,400 KB
testcase_26 AC 20 ms
23,544 KB
testcase_27 AC 20 ms
23,352 KB
testcase_28 AC 20 ms
23,520 KB
testcase_29 AC 19 ms
23,352 KB
testcase_30 AC 21 ms
23,688 KB
testcase_31 AC 20 ms
24,348 KB
testcase_32 AC 21 ms
23,964 KB
testcase_33 AC 20 ms
23,628 KB
testcase_34 AC 20 ms
23,808 KB
testcase_35 AC 20 ms
23,532 KB
testcase_36 AC 20 ms
23,400 KB
testcase_37 AC 21 ms
23,616 KB
testcase_38 AC 20 ms
23,376 KB
testcase_39 AC 20 ms
23,784 KB
testcase_40 AC 21 ms
23,976 KB
testcase_41 AC 22 ms
23,508 KB
testcase_42 AC 19 ms
24,204 KB
testcase_43 AC 19 ms
23,604 KB
testcase_44 AC 19 ms
23,628 KB
testcase_45 AC 19 ms
23,736 KB
testcase_46 AC 20 ms
23,376 KB
testcase_47 AC 20 ms
23,352 KB
testcase_48 AC 20 ms
23,808 KB
testcase_49 AC 20 ms
24,288 KB
testcase_50 AC 21 ms
23,976 KB
testcase_51 AC 20 ms
24,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer::n(1:4),m(1:4)
  integer::hit,blow,hb,i,j
  data n/0,1,2,3/

  call get(n,hit,blow)
  if(hit.eq.4) return

! selection
  if(hit+blow.ne.4) then
     hb = hit+blow
     do i=1,4
        m = n
        do j=0,9
           if(ANY(n.eq.j)) cycle
           m(i) = j
           call get(m,hit,blow)
           if(hit.eq.4) then
              return
           else if(hit+blow.eq.4) then
              n = m
              goto 10
           else if(hit+blow.gt.hb) then
              hb = hit + blow
              n = m
              exit
           end if
        end do
     end do
  end if
10 continue
  ! shuffle
  m = n
  n = qsort(m)
  do
     call get(n,hit,blow)
     if(hit.eq.4) then
        return
     end if
     call next_permutation(n)
  end do
contains
  subroutine get(n,hit,blow)
    integer::n(1:4)
    integer::hit,blow
    print '(i0," ",i0," ",i0," ",i0)',n
    read *,hit,blow
  end subroutine get
  subroutine next_permutation(array)
    implicit none
    integer::array(:),d,i,j,k,swap
    d = 4

    do i=d,2,-1
       if(array(i-1).lt.array(i)) exit
    end do
    do j=d,i+1,-1
       if(array(i-1).lt.array(j)) exit
    end do

    swap       = array(i-1)
    array(i-1) = array(j)
    array(j)   = swap
    do k=0, (d-1-i)/2
       swap       = array(i+k)
       array(i+k) = array(d-k)
       array(d-k) = swap
    end do
  end subroutine next_permutation
  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