結果

問題 No.140 みんなで旅行
ユーザー 37zigen37zigen
提出日時 2018-04-21 18:48:20
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 1,048 ms / 5,000 ms
コード長 1,223 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 28,468 KB
実行使用メモリ 7,436 KB
最終ジャッジ日時 2023-09-09 12:22:42
合計ジャッジ時間 6,541 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 9 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1,048 ms
7,360 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1,046 ms
7,436 KB
testcase_15 AC 1,035 ms
7,408 KB
testcase_16 AC 240 ms
6,664 KB
testcase_17 AC 62 ms
6,336 KB
testcase_18 AC 659 ms
6,780 KB
testcase_19 AC 828 ms
7,020 KB
testcase_20 AC 43 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #



program main
    implicit none
    integer*8::n,f(0:1,0:560,0:560),i,j,k,ans
    integer*8,parameter::mo=1000000007
    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)=f(ne,j+1,k)+f(cur,j,k)
                    if(f(ne,j+1,k)>=mo)f(ne,j+1,k)=f(ne,j+1,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)=f(ne,j,k+2)+f(cur,j,k)
                    if(f(ne,j,k+2)>=mo)f(ne,j,k+2)=f(ne,j,k+2)-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=ans+f(mod(n,2),i,0)
        if(ans>=mo)ans=ans-mo
    end do
    print*,ans
end program
0