結果
問題 | No.90 品物の並び替え |
ユーザー |
![]() |
提出日時 | 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 mainimplicit noneinteger*8::N,Minteger*8::i,ii,jj,ss,maxscoreinteger*8,parameter::d = 9integer*8::score(d,d),items(d)data score/81*0/items = (/(i,i=1,d)/)read *,N,Mdo i=1,Mread *,ii,jj,ssscore(ii+1,jj+1) = ssend domaxscore = 0domaxscore = MAX(maxscore, get_scores(items, score, N))if(.not.(next_permutation(items, d))) exitend doprint '(i0)', maxscorecontainsfunction get_scores(items, score, d) result(total)integer*8::total,i,j,dinteger*8,intent(in)::score(:,:), items(:)total = 0do i=1,d-1do j=i,dtotal = score(items(i), items(j)) + totalend doend doend function get_scoresfunction next_permutation(array, d) result(notlast)logical::notlastinteger*8::array(:),d,i,j,k,swapdo i=d,2,-1if(array(i-1).lt.array(i)) exitend doif(i.eq.1) thennotlast = .false.returnelsenotlast = .true.end ifdo j=d,i+1,-1if(array(i-1).lt.array(j)) exitend doswap = array(i-1)array(i-1) = array(j)array(j) = swapdo k=0, (d-1-i)/2swap = array(i+k)array(i+k) = array(d-k)array(d-k) = swapend doend function next_permutationend program main