Submission #4678356


Source Code Expand

program twin_and_ox_game
  implicit none
  integer :: b(2,3), c(3,2), g(3,3)
  integer :: bro, sis
  b = 0
  c = 0
  read(*,*) b(1,1), b(1,2), b(1,3)
  read(*,*) b(2,1), b(2,2), b(2,3)
  read(*,*) c(1,1), c(1,2)
  read(*,*) c(2,1), c(2,2)
  read(*,*) c(3,1), c(3,2)
  g = 0
  bro = 0
  sis = 0
  call get_score(b,c,g,bro,sis,0)
  write(*,'(i0)') bro
  write(*,'(i0)') sis
  stop
contains
  recursive subroutine get_score(b,c,g,bro,sis,n)
    implicit none
    integer, intent(in)    :: b(2,3), c(3,2), g(3,3), n
    integer, intent(inout) :: bro, sis
    integer                :: i, j, s, h(3,3), ix, jx
    integer                :: tbro, tsis
    if (n.eq.9) then
      bro = 0
      sis = 0
      do i = 1, 2
        do j = 1, 3
          if ((g(i,j).ne.0).and.(g(i,j).eq.g(i+1,j))) then
            bro = bro + b(i,j)
          else
            sis = sis + b(i,j)
          end if
          if ((g(j,i).ne.0).and.g(j,i).eq.g(j,i+1)) then
            bro = bro + c(j,i)
          else
            sis = sis + c(j,i)
          end if
        end do
      end do
      return
    end if
    if (mod(n,2).eq.0) then
      s = -2000000
      do i = 1, 3
        do j = 1, 3
          if (g(i,j).eq.0) then
            h = g
            h(i,j) = 1
            call get_score(b,c,h,tbro,tsis,n+1)
            if (tbro-tsis.gt.s) then
              s = tbro-tsis
              ix = i
              jx = j
            end if
          end if
        end do
      end do
      h = g
      h(ix,jx) = 1
      call get_score(b,c,h,bro,sis,n+1)
    else
      s = 2000000
      do i = 1, 3
        do j = 1, 3
          if (g(i,j).eq.0) then
            h = g
            h(i,j) = -1
            call get_score(b,c,h,tbro,tsis,n+1)
            if (tbro-tsis.lt.s) then
              s = tbro-tsis
              ix = i
              jx = j
            end if
          end if
        end do
      end do
      h = g
      h(ix,jx) = -1
      call get_score(b,c,h,bro,sis,n+1)
    end if
    return
  end subroutine get_score
end program twin_and_ox_game

Submission Info

Submission Time
Task C - 双子と○×ゲーム
User ue1221
Language Fortran (gfortran v4.8.4)
Score 100
Code Size 2129 Byte
Status AC
Exec Time 159 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample-01.txt, sample-02.txt
All sample-01.txt, sample-02.txt, test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
sample-01.txt AC 157 ms 256 KB
sample-02.txt AC 158 ms 256 KB
test-01.txt AC 157 ms 256 KB
test-02.txt AC 158 ms 256 KB
test-03.txt AC 157 ms 256 KB
test-04.txt AC 159 ms 256 KB
test-05.txt AC 157 ms 256 KB
test-06.txt AC 157 ms 256 KB
test-07.txt AC 157 ms 256 KB
test-08.txt AC 158 ms 256 KB
test-09.txt AC 158 ms 256 KB
test-10.txt AC 157 ms 256 KB
test-11.txt AC 155 ms 256 KB
test-12.txt AC 157 ms 256 KB
test-13.txt AC 157 ms 256 KB
test-14.txt AC 157 ms 256 KB
test-15.txt AC 157 ms 256 KB
test-16.txt AC 157 ms 256 KB
test-17.txt AC 156 ms 256 KB
test-18.txt AC 157 ms 256 KB
test-19.txt AC 157 ms 256 KB
test-20.txt AC 157 ms 256 KB