結果

問題 No.90 品物の並び替え
ユーザー jjjj
提出日時 2016-10-16 22:37:13
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,306 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 32,640 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 02:46:16
合計ジャッジ時間 1,136 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 17 ms
5,376 KB
testcase_02 AC 6 ms
5,376 KB
testcase_03 AC 14 ms
5,376 KB
testcase_04 AC 14 ms
5,376 KB
testcase_05 AC 16 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 12 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 21 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer*8::N,M
  integer*8::i,ii,jj,ss,maxscore
  integer*8,parameter::d = 9
  integer*8::score(d,d),items(d)
  data score/81*0/
  items = (/(i,i=1,d)/)
  read *,N,M

  do i=1,M
     read *,ii,jj,ss
     score(ii+1,jj+1) = ss
  end do
  maxscore = 0
  do
     maxscore = MAX(maxscore, get_scores(items, score, N))
     if(.not.(next_permutation(items, d))) exit
  end do
  print '(i0)', maxscore
contains
  function get_scores(items, score, d) result(total)
    integer*8::total,i,j,d
    integer*8,intent(in)::score(:,:), items(:)
    total = 0
    do i=1,d-1
       do j=i,d
          total = score(items(i), items(j)) + total
       end do
    end do
  end function get_scores
  function next_permutation(array, d) result(notlast)
    logical::notlast
    integer*8::array(:),d,i,j,k,swap

    do i=d,2,-1
       if(array(i-1).lt.array(i)) exit
    end do
    if(i.eq.1) then
       notlast = .false.
       return
    else
       notlast = .true.
    end if
    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 function next_permutation
end program main
0