답안 #913817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913817 2024-01-20T09:58:26 Z alexdd Tents (JOI18_tents) C++17
48 / 100
2000 ms 28316 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
int n,m;
int dp[2][3005][3005];
int put(int a, int exp)
{
    if(exp==0)
        return 1;
    if(exp%2==0)
        return put((a*a)%MOD,exp/2);
    else
        return (put((a*a)%MOD,exp/2)*a)%MOD;
}
signed main()
{
    cin>>n>>m;
    dp[0][0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int cnt1=0;cnt1<=min(m,i);cnt1++)
        {
            for(int cnti=0;cnti<=min(2*i,m-cnt1);cnti++)
            {
                dp[i%2][cnt1][cnti] = dp[1-i%2][cnt1][cnti];///daca nu punem niciun cort pe linia i
                if(cnt1-1>=0) dp[i%2][cnt1][cnti] += dp[1-i%2][cnt1-1][cnti] * (m-cnti-cnt1+1);
                if(cnti-1>=0) dp[i%2][cnt1][cnti] += dp[1-i%2][cnt1+1][cnti-1] * (cnt1+1);
                if(cnti-2>=0) dp[i%2][cnt1][cnti] += (dp[1-i%2][cnt1][cnti-2] * (m-cnt1-cnti+2)*(m-cnt1-cnti+1)/2)%MOD;
                dp[i%2][cnt1][cnti] %= MOD;
            }
        }
    }
    int sum=MOD-1;
    for(int cnt1=0;cnt1<=m;cnt1++)
        for(int cnti=0;cnti+cnt1<=m;cnti++)
            sum = (sum + (dp[n%2][cnt1][cnti] * put(4,cnt1))%MOD)%MOD;
    cout<<sum;
    return 0;
}
/**

dp[i][cnt1][cnti] = numarul de moduri de a pune corturi pe primele i randuri a.i. sa avem cnt1 coloane cu un cort pe ele si cnti coloane interzise (pe care nu mai putem pune corturi)
dp[i][cnt1][cnti] = dp[i-1][cnt1][cnti] + dp[i-1][cnt1-1][cnti] * (m - cnti - cnt1 + 1) + dp[i-1][cnt1+1][cnti-1] * (cnt1+1) + dp[i-1][cnt1][cnti-2] * (m-cnt1-cnti+2) * (m-cnt1-cnti+1) / 2

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 3 ms 2648 KB Output is correct
6 Correct 5 ms 2908 KB Output is correct
7 Correct 4 ms 2908 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 13 ms 3308 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 46 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 3 ms 2648 KB Output is correct
6 Correct 5 ms 2908 KB Output is correct
7 Correct 4 ms 2908 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 13 ms 3308 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 46 ms 5456 KB Output is correct
13 Correct 72 ms 2504 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Execution timed out 2052 ms 28316 KB Time limit exceeded
16 Halted 0 ms 0 KB -