結果
問題 | No.355 数当てゲーム(2) |
ユーザー |
![]() |
提出日時 | 2017-01-08 07:30:26 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 1,815 bytes |
コンパイル時間 | 805 ms |
コンパイル使用メモリ | 35,776 KB |
実行使用メモリ | 25,488 KB |
平均クエリ数 | 24.96 |
最終ジャッジ日時 | 2024-07-17 00:44:33 |
合計ジャッジ時間 | 5,154 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
program mainimplicit noneinteger::n(1:4),m(1:4)integer::hit,blow,hb,i,jdata n/0,1,2,3/call get(n,hit,blow)if(hit.eq.4) return! selectionif(hit+blow.ne.4) thenhb = hit+blowdo i=1,4m = ndo j=0,9if(ANY(n.eq.j)) cyclem(i) = jcall get(m,hit,blow)if(hit.eq.4) thenreturnelse if(hit+blow.eq.4) thenn = mgoto 10else if(hit+blow.gt.hb) thenhb = hit + blown = mexitend ifend doend doend if10 continue! shufflem = nn = qsort(m)docall get(n,hit,blow)if(hit.eq.4) thenreturnend ifcall next_permutation(n)end docontainssubroutine get(n,hit,blow)integer::n(1:4)integer::hit,blowprint '(i0," ",i0," ",i0," ",i0)',nread *,hit,blowend subroutine getsubroutine next_permutation(array)implicit noneinteger::array(:),d,i,j,k,swapd = 4do i=d,2,-1if(array(i-1).lt.array(i)) exitend dodo j=d,i+1,-1if(array(i-1).lt.array(j)) exitend doswap = array(i-1)array(i-1) = array(j)array(j) = swapdo k=0, (d-1-i)/2swap = array(i+k)array(i+k) = array(d-k)array(d-k) = swapend doend subroutine next_permutationrecursive function qsort(x) result(y)integer,intent(in) ::x(:)integer,allocatable::y(:)integer::pivot,totaltotal = size(x)if (total <=1) theny = xelsepivot = x(total/2)y = [qsort(pack(x, x .lt. pivot)), &pack(x, x .eq. pivot), &qsort(pack(x, x .gt. pivot))]endifend function qsortend program main