Submission #6480100


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, K;
mint dp[51][51][3100];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	dp[0][0][0] = 1;
	rep(i, 0, N) rep(rest, 0, N) rep(k, 0, K + 1) {
		// どちらの順列のi + 1番目も使わない
		dp[i + 1][rest + 1][k + 2 * rest + 2] += dp[i][rest][k];

		// 順列Aのi + 1番目と、順列Bの残りとマッチングさせる
		if (rest) dp[i + 1][rest][k + 2 * rest] += dp[i][rest][k] * rest;

		// 順列Bのi + 1番目と、順列Aの残りとマッチングさせる
		if (rest) dp[i + 1][rest][k + 2 * rest] += dp[i][rest][k] * rest;

		// 順列Aのi + 1番目と、順列Bのi + 1番目とマッチングさせる
		dp[i + 1][rest][k + 2 * rest] += dp[i][rest][k];
		
		// 順列Aのi + 1番目と順列Bの残り、順列Bのi + 1番目と順列Aの残りとマッチングさせる
		if(rest) dp[i + 1][rest - 1][k + 2 * rest - 2] += dp[i][rest][k] * rest * rest;
	}
	cout << dp[N][0][K] << endl;
}





Submission Info

Submission Time
Task F - Permutation Oddness
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 600
Code Size 3983 Byte
Status
Exec Time 65 ms
Memory 31744 KB

Test Cases

Set Name Score / Max Score Test Cases
All 600 / 600 sample_01, sample_02, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_2, testcase_20, testcase_21, testcase_22, testcase_23, testcase_24, testcase_25, testcase_26, testcase_27, testcase_28, testcase_29, testcase_3, testcase_30, testcase_31, testcase_32, testcase_33, testcase_34, testcase_35, testcase_36, testcase_37, testcase_38, testcase_39, testcase_4, testcase_40, testcase_41, testcase_42, testcase_43, testcase_44, testcase_45, testcase_46, testcase_47, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9
Sample 0 / 0 sample_01, sample_02
Case Name Status Exec Time Memory
sample_01 11 ms 31744 KB
sample_02 11 ms 31744 KB
testcase_0 17 ms 31744 KB
testcase_1 13 ms 31744 KB
testcase_10 11 ms 31744 KB
testcase_11 18 ms 31744 KB
testcase_12 11 ms 31744 KB
testcase_13 11 ms 31744 KB
testcase_14 26 ms 31744 KB
testcase_15 20 ms 31744 KB
testcase_16 11 ms 31744 KB
testcase_17 12 ms 31744 KB
testcase_18 20 ms 31744 KB
testcase_19 11 ms 31744 KB
testcase_2 11 ms 31744 KB
testcase_20 11 ms 31744 KB
testcase_21 14 ms 31744 KB
testcase_22 11 ms 31744 KB
testcase_23 12 ms 31744 KB
testcase_24 11 ms 31744 KB
testcase_25 13 ms 31744 KB
testcase_26 14 ms 31744 KB
testcase_27 12 ms 31744 KB
testcase_28 11 ms 31744 KB
testcase_29 12 ms 31744 KB
testcase_3 11 ms 31744 KB
testcase_30 11 ms 31744 KB
testcase_31 16 ms 31744 KB
testcase_32 10 ms 31744 KB
testcase_33 11 ms 31744 KB
testcase_34 11 ms 31744 KB
testcase_35 11 ms 31744 KB
testcase_36 11 ms 31744 KB
testcase_37 11 ms 31744 KB
testcase_38 11 ms 31744 KB
testcase_39 11 ms 31744 KB
testcase_4 22 ms 31744 KB
testcase_40 10 ms 31744 KB
testcase_41 37 ms 31744 KB
testcase_42 37 ms 31744 KB
testcase_43 11 ms 31744 KB
testcase_44 11 ms 31744 KB
testcase_45 40 ms 31744 KB
testcase_46 40 ms 31744 KB
testcase_47 65 ms 31744 KB
testcase_5 15 ms 31744 KB
testcase_6 11 ms 31744 KB
testcase_7 11 ms 31744 KB
testcase_8 10 ms 31744 KB
testcase_9 56 ms 31744 KB