답안 #816915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
816915 2023-08-09T07:28:21 Z MohamedAhmed04 Tents (JOI18_tents) C++14
100 / 100
79 ms 35576 KB
#include <bits/stdc++.h>

using namespace std ;

const int mod = 1e9 + 7 ;

int Add(int x , int y)
{
	int z = x + y ;
	if(z >= mod)
		z -= mod ;
	return z ;
}

int Sub(int x , int y)
{
	int z = x - y ;
	if(z < 0)
		z += mod ;
	return z ;
}

int Mul(int x , int y)
{
	return (1ll * x * y) % mod ;
}

const int MAX = 3000 + 10 ;

int arr[MAX] ;
int n , m ;

int dp[MAX][MAX] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i <= max(n , m) ; ++i)
		dp[0][i] = dp[i][0] = 1 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		for(int j = 1 ; j <= m ; ++j)
		{
			dp[i][j] = Add(dp[i-1][j] , Mul(dp[i-1][j-1] , 4*j)) ;
			if(j >= 2)
				dp[i][j] = Add(dp[i][j] , Mul(dp[i-1][j-2] , j * (j-1) / 2)) ;
			if(i >= 2)
				dp[i][j] = Add(dp[i][j] , Mul(dp[i-2][j-1] , (i-1) * j)) ;
		}
	}
	return cout<<Sub(dp[n][m] , 1)<<"\n" , 0 ;
}		
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1360 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1352 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 1612 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1360 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1352 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 1612 KB Output is correct
11 Correct 1 ms 1492 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 3 ms 7636 KB Output is correct
14 Correct 4 ms 9544 KB Output is correct
15 Correct 57 ms 32792 KB Output is correct
16 Correct 7 ms 7892 KB Output is correct
17 Correct 13 ms 12408 KB Output is correct
18 Correct 16 ms 11716 KB Output is correct
19 Correct 78 ms 34508 KB Output is correct
20 Correct 47 ms 29120 KB Output is correct
21 Correct 32 ms 21504 KB Output is correct
22 Correct 31 ms 22160 KB Output is correct
23 Correct 20 ms 19668 KB Output is correct
24 Correct 79 ms 35576 KB Output is correct
25 Correct 64 ms 30772 KB Output is correct
26 Correct 78 ms 33484 KB Output is correct
27 Correct 77 ms 34840 KB Output is correct