Submission #897747

# Submission time Handle Problem Language Result Execution time Memory
897747 2024-01-03T15:56:12 Z denniskim NoM (RMI21_nom) C++17
100 / 100
90 ms 99668 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
 
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
 
ll n, m;
ll ss = 1000000007;
int ans;
ll cou[2010];
int dp[9000010];
ll fac[5010] = {0, }, inv[5010] = {0, };
int C[5010][5010];
 
ll num(ll X, ll Y)
{
	return X * (m + 1) + Y;
}

void init(void)
{
	fac[0] = 1;
    fac[1] = 1;
     
    for(ll i = 2 ; i <= 4500 ; ++i)
        fac[i] = (fac[i - 1] * i) % ss;
    
    C[0][0] = 1;
    
    for(ll i = 1 ; i <= 4000 ; ++i)
    {
    	C[i][0] = C[i][i] = 1;
    	
    	for(ll j = 1 ; j < i ; ++j)
    	{
    		C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    		
    		if(C[i][j] > ss)
    			C[i][j] -= ss;
		}
	}
}
 
int main(void)
{
	fastio
	
	cin >> n >> m;
	
	init();
	
	ll siz = (n << 1);
	
	ans = fac[siz];
	
	for(ll i = 1 ; i <= siz ; ++i)
	{
		ll gap = i % m;
		
		if(gap == 0)
			gap = m;
		
		cou[gap]++;
	}
	
	for(ll i = 0 ; i <= m ; ++i)
		dp[num(0, i)] = 1;
	
	for(ll i = 1 ; i <= n ; ++i)
	{
		for(ll j = 1 ; j <= m ; ++j)
		{
			ll X = cou[j];
			
			for(ll k = 1 ; (k << 1) <= X && k <= i ; ++k)
            {
				dp[num(i, j)] = (dp[num(i, j)] + (ll)dp[num(i - k, j - 1)] * C[X][k << 1] % ss * fac[k << 1] % ss * C[i][k]% ss);
              	while(abs(dp[num(i, j)]) > ss)
                {
                    if(dp[num(i, j)] < 0)
                        dp[num(i, j)] += ss;
                    else
                        dp[num(i, j)] -= ss;
                }
            }
		}
		
		for(ll j = 1 ; j <= m ; ++j)
        {
			dp[num(i, j)] = (dp[num(i, j)] + dp[num(i, j - 1)]);
          
          	while(abs(dp[num(i, j)]) > ss)
			{
				if(dp[num(i, j)] < 0)
					dp[num(i, j)] += ss;
				else
					dp[num(i, j)] -= ss;
			}
        }
	}
	
	for(ll i = 1 ; i <= n ; ++i)
	{
		ll gap = (ll)dp[num(i, m)] * C[n][i] % ss * fac[(n - i) << 1] % ss;
		
		if(i & 1)
			ans = (ans - gap);
		else
			ans = (ans + gap);
      
      	while(abs(ans) > ss)
        {
          if(ans < 0)
            ans += ss;
          else
            ans -= ss;
        }
	}
	
	ans = (ans + ss) % ss;
	
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84604 KB Output is correct
3 Correct 14 ms 84572 KB Output is correct
4 Correct 13 ms 84572 KB Output is correct
5 Correct 14 ms 84596 KB Output is correct
6 Correct 13 ms 84572 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 14 ms 84572 KB Output is correct
9 Correct 14 ms 84492 KB Output is correct
10 Correct 14 ms 84572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84604 KB Output is correct
3 Correct 14 ms 84572 KB Output is correct
4 Correct 13 ms 84572 KB Output is correct
5 Correct 14 ms 84596 KB Output is correct
6 Correct 13 ms 84572 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 14 ms 84572 KB Output is correct
9 Correct 14 ms 84492 KB Output is correct
10 Correct 14 ms 84572 KB Output is correct
11 Correct 15 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84572 KB Output is correct
14 Correct 14 ms 84564 KB Output is correct
15 Correct 14 ms 84564 KB Output is correct
16 Correct 14 ms 84572 KB Output is correct
17 Correct 14 ms 84536 KB Output is correct
18 Correct 14 ms 84572 KB Output is correct
19 Correct 14 ms 84616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84604 KB Output is correct
3 Correct 14 ms 84572 KB Output is correct
4 Correct 13 ms 84572 KB Output is correct
5 Correct 14 ms 84596 KB Output is correct
6 Correct 13 ms 84572 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 14 ms 84572 KB Output is correct
9 Correct 14 ms 84492 KB Output is correct
10 Correct 14 ms 84572 KB Output is correct
11 Correct 15 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84572 KB Output is correct
14 Correct 14 ms 84564 KB Output is correct
15 Correct 14 ms 84564 KB Output is correct
16 Correct 14 ms 84572 KB Output is correct
17 Correct 14 ms 84536 KB Output is correct
18 Correct 14 ms 84572 KB Output is correct
19 Correct 14 ms 84616 KB Output is correct
20 Correct 15 ms 84572 KB Output is correct
21 Correct 15 ms 84824 KB Output is correct
22 Correct 15 ms 84572 KB Output is correct
23 Correct 15 ms 84828 KB Output is correct
24 Correct 15 ms 84572 KB Output is correct
25 Correct 15 ms 84572 KB Output is correct
26 Correct 15 ms 84568 KB Output is correct
27 Correct 15 ms 84572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84604 KB Output is correct
3 Correct 14 ms 84572 KB Output is correct
4 Correct 13 ms 84572 KB Output is correct
5 Correct 14 ms 84596 KB Output is correct
6 Correct 13 ms 84572 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 14 ms 84572 KB Output is correct
9 Correct 14 ms 84492 KB Output is correct
10 Correct 14 ms 84572 KB Output is correct
11 Correct 15 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84572 KB Output is correct
14 Correct 14 ms 84564 KB Output is correct
15 Correct 14 ms 84564 KB Output is correct
16 Correct 14 ms 84572 KB Output is correct
17 Correct 14 ms 84536 KB Output is correct
18 Correct 14 ms 84572 KB Output is correct
19 Correct 14 ms 84616 KB Output is correct
20 Correct 15 ms 84572 KB Output is correct
21 Correct 15 ms 84824 KB Output is correct
22 Correct 15 ms 84572 KB Output is correct
23 Correct 15 ms 84828 KB Output is correct
24 Correct 15 ms 84572 KB Output is correct
25 Correct 15 ms 84572 KB Output is correct
26 Correct 15 ms 84568 KB Output is correct
27 Correct 15 ms 84572 KB Output is correct
28 Correct 23 ms 84572 KB Output is correct
29 Correct 21 ms 85096 KB Output is correct
30 Correct 21 ms 85596 KB Output is correct
31 Correct 23 ms 84572 KB Output is correct
32 Correct 24 ms 85084 KB Output is correct
33 Correct 26 ms 85840 KB Output is correct
34 Correct 30 ms 87388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84604 KB Output is correct
3 Correct 14 ms 84572 KB Output is correct
4 Correct 13 ms 84572 KB Output is correct
5 Correct 14 ms 84596 KB Output is correct
6 Correct 13 ms 84572 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 14 ms 84572 KB Output is correct
9 Correct 14 ms 84492 KB Output is correct
10 Correct 14 ms 84572 KB Output is correct
11 Correct 15 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84572 KB Output is correct
14 Correct 14 ms 84564 KB Output is correct
15 Correct 14 ms 84564 KB Output is correct
16 Correct 14 ms 84572 KB Output is correct
17 Correct 14 ms 84536 KB Output is correct
18 Correct 14 ms 84572 KB Output is correct
19 Correct 14 ms 84616 KB Output is correct
20 Correct 15 ms 84572 KB Output is correct
21 Correct 15 ms 84824 KB Output is correct
22 Correct 15 ms 84572 KB Output is correct
23 Correct 15 ms 84828 KB Output is correct
24 Correct 15 ms 84572 KB Output is correct
25 Correct 15 ms 84572 KB Output is correct
26 Correct 15 ms 84568 KB Output is correct
27 Correct 15 ms 84572 KB Output is correct
28 Correct 23 ms 84572 KB Output is correct
29 Correct 21 ms 85096 KB Output is correct
30 Correct 21 ms 85596 KB Output is correct
31 Correct 23 ms 84572 KB Output is correct
32 Correct 24 ms 85084 KB Output is correct
33 Correct 26 ms 85840 KB Output is correct
34 Correct 30 ms 87388 KB Output is correct
35 Correct 67 ms 84620 KB Output is correct
36 Correct 71 ms 96004 KB Output is correct
37 Correct 66 ms 84600 KB Output is correct
38 Correct 65 ms 89424 KB Output is correct
39 Correct 58 ms 93476 KB Output is correct
40 Correct 90 ms 99668 KB Output is correct