結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
jj
|
| 提出日時 | 2017-02-04 00:21:07 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,827 bytes |
| コンパイル時間 | 329 ms |
| コンパイル使用メモリ | 34,048 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-24 06:00:15 |
| 合計ジャッジ時間 | 1,128 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
コンパイルメッセージ
Main.f90:67:30:
67 | write(cformat(5:9),'(i0)'),size(array)
| 1
Warning: Legacy Extension: Comma before i/o item list at (1)
ソースコード
program main
implicit none
integer::N,depth=0
integer::K(12)
logical::flag
read *,N
read *,K(1:N)
flag = win(K(1:N), depth)
if(flag.eqv..false.) print '("-1")'
contains
logical recursive function win(K, depth) result(w)
integer::K(:)
integer,allocatable::L(:)
integer::a,b,c,s,ka,kb,kc, depth
logical,allocatable::mask(:)
s = SIZE(K)
if(s.le.2) then
w = .false.
return
else
allocate(mask(s))
allocate(L(s-3))
mask = .true.
do a=1,s-2
ka = K(a)
do b=a+1,s-1
kb = K(b)
if(kb.eq.ka) cycle
do c=b+1,s
kc = K(c)
!print '(i0,":",3(i0,1x),":",3(i0,1x))',depth,a,b,c, ka,kb,kc
if(.not.is_kadomatsu(ka,kb,kc)) cycle
mask(a)=.false.
mask(b)=.false.
mask(c)=.false.
L = PACK(K,mask)
if(win(L, depth+1).eqv..false.) then
w = .true.
if(depth.eq.0) then
print '(3(i0,1x))', a-1,b-1,c-1
end if
return
end if
mask(c)=.true.
end do
mask(b)=.true.
end do
mask(a)=.true.
end do
w = .false.
end if
end function win
logical function is_kadomatsu(a,b,c) result(k)
integer::a,b,c
if(a.eq.b.or.b.eq.c.or.a.eq.b.or. &
(a.gt.b.and.b.gt.c) .or. &
(a.lt.b.and.b.lt.c)) then
k = .false.
else
k = .true.
end if
end function is_kadomatsu
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