結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
jj
|
| 提出日時 | 2016-10-16 22:37:13 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 5,000 ms |
| コード長 | 1,306 bytes |
| コンパイル時間 | 1,515 ms |
| コンパイル使用メモリ | 32,384 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-22 12:39:59 |
| 合計ジャッジ時間 | 2,745 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
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
jj