結果

問題 No.140 みんなで旅行
ユーザー 37zigen37zigen
提出日時 2018-04-21 18:42:51
言語 Fortran
(gFortran 13.2.0)
結果
RE  
実行時間 -
コード長 1,197 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 28,488 KB
実行使用メモリ 9,716 KB
最終ジャッジ日時 2023-09-09 12:22:05
合計ジャッジ時間 6,498 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 10 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 RE -
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 RE -
testcase_15 AC 1,078 ms
7,312 KB
testcase_16 AC 228 ms
6,672 KB
testcase_17 AC 68 ms
6,344 KB
testcase_18 AC 650 ms
6,736 KB
testcase_19 AC 762 ms
6,976 KB
testcase_20 AC 45 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
    implicit none
    integer*8::n,f(0:1,0:555,0:555),i,j,k,ans
    integer*8,parameter::mo=1000000007
    !f(i,j)=夫婦の揃っているグループがiグループ、揃っていないグループがjグループ
    read*,n
    do i=0,n
        do j=0,n
            f(0,i,j)=0
        end do
    end do
    f(0,0,0)=1
    block
        integer::cur,ne
        do i=1,n
            cur=mod(i-1,2)
            ne=mod(cur+1,2)
            do j=0,j
                do k=0,n
                    f(ne,j,k)=0
                end do
            end do
            do j=0,n
                do k=0,n
                    if(f(cur,j,k)==0)cycle
                    f(ne,j,k)=mod(f(ne,j,k)+f(cur,j,k)*j*j+f(cur,j,k)*k*(k-1)+f(cur,j,k)*k*j*2,mo)
                    f(ne,j+1,k)=mod(f(ne,j+1,k)+f(cur,j,k),mo)
                    f(ne,j,k+1)=mod(f(ne,j,k+1)+f(cur,j,k)*(j+k)*2,mo)
                    f(ne,j,k+2)=mod(f(ne,j,k+2)+f(cur,j,k),mo)
                    if(k>0)f(ne,j+1,k-1)=mod(f(ne,j+1,k-1)+f(cur,j,k)*k,mo)
                end do
            end do
        end do
    end block

    ans=0
    do i=1,n
        ans=mod(ans+f(mod(n,2),i,0),mo)
    end do
    print*,ans
end program
0