結果

問題 No.43 野球の試合
ユーザー jjjj
提出日時 2017-01-29 04:33:18
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,892 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 29,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 14:17:11
合計ジャッジ時間 901 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.f90:83:30:

     write(cformat(5:9),'(i0)'),size(array)
                              1
Warning: Legacy Extension: Comma before i/o item list at (1)

ソースコード

diff #

program main
  implicit none
  integer::N,i,j,tmp,num,minnum
  character::c
  character*6::S(6)
  integer*8,allocatable::games(:,:)
  integer*8,parameter::win=2,lose=0,self=9, none=1
  type game
     integer::a,b
  end type game
  type(game)::yet(15)
  yet(:)%a=0
  yet(:)%b=0

  read *,N
  allocate(games(1:N,1:N))
  read *,S(1:N)(1:N)

  do i=1,N
     games(i,i) = self
     do j=i+1,N
        c = S(i)(j:j)
        if(c.eq.'o') then
           games(i,j) = win
           games(j,i) = lose
        else if(c.eq.'x') then
           games(i,j) = lose
           games(j,i) = win
        else
           games(i,j) = none
           games(j,i) = none
        end if
     end do
  end do

  num = 0
  do i=1, N
     do j=i+1, N
        if(games(i,j).eq.none) then
           num = num + 1
           yet(num)%a = i
           yet(num)%b = j
        end if
     end do
  end do

  if(num.eq.N*(N-1)/2) then
     print '(i0)', 1
     return
  else if(num.eq.0) then
     print '(i0)', get_grade()
     return
  endif
  minnum = N
  do i=0, 2**num-1
     do j=0, num-1
        if(btest(i, j).eqv..true.) then
           games(yet(j+1)%a,yet(j+1)%b) = win
           games(yet(j+1)%b,yet(j+1)%a) = lose
        else
           games(yet(j+1)%a,yet(j+1)%b) = lose
           games(yet(j+1)%b,yet(j+1)%a) = win
        end if
     end do
     minnum = MIN(minnum, get_grade())
  end do
  print '(i0)', minnum

contains
  function get_grade() result(w)
    integer::i,w
    integer::grades(0:N+1),winnum
    grades = 0
    winnum = COUNT(games(1,:).eq.win)
    do i=2,N
       grades(COUNT(games(i,:).eq.win)) = 1
    end do
    w = SUM(grades(winnum+1:N+1)) + 1
  end function get_grade
  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
0