답안 #890577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890577 2023-12-21T13:48:45 Z fanwen NoM (RMI21_nom) C++17
0 / 100
2 ms 1116 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define file(name)                  \
    if(fopen(name".inp", "r"))      \
        freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); 

template <int Mod> 
struct Modular {
private :
    int val;
    static int inverse(int a, int b) {
        a %= b;
        assert(a);
        if(a == 1) return 1;
        return int(b - (long long) inverse(b, a) * (long long) b / a);
    }
public :
    Modular(long long x = 0) : val(x % Mod) { if(val < 0) val += Mod; }

    friend bool operator == (const Modular &a, const Modular &b) { return a.val == b.val; }
    friend bool operator != (const Modular &a, const Modular &b) { return a.val != b.val; }

    Modular& operator = (const long long &x) { val = x % Mod; if(val < 0) val += Mod; return *this; }
    Modular& operator = (const Modular &x) { val = x.val; return *this; }

    friend istream & operator >> (istream &in, Modular &a) { long long x; in >> x; a = Modular(x); return in; }
    friend ostream & operator << (ostream &out, const Modular &a) { return out << a.val; }

    explicit operator int() const { return val; }
    explicit operator bool() const { return val > 0; }

    Modular inv() const {
        Modular res;
        res.val = inverse(val, Mod);
        return res;
    }

    Modular operator ++() { (*this) += 1; return *this; }
    Modular operator --() { (*this) -= 1; return *this; }
    Modular operator ++(int) { (*this) += 1; return *this - 1; }
    Modular operator --(int) { (*this) -= 1; return *this + 1; }

    Modular operator + () const { return *this; }
    Modular operator - () const {
        Modular res;
        res.val = (val ? Mod - val : 0);
        return res;
    }

    Modular& operator += (const Modular &a) {
        val += a.val;
        if(val >= Mod) val -= Mod;
        return *this;
    }
    Modular& operator -= (const Modular &a) {
        val -= a.val;
        if(val < 0) val += Mod;
        return *this;
    }
    Modular& operator *= (const Modular &a) {
        val = 1LL * val * a.val % Mod;
        return *this;
    }
    Modular& operator /= (const Modular &a) {
        (*this) *= a.inv();
        return *this;
    }
    friend Modular operator + (const Modular &a, const Modular &b) { return Modular(a) += b; }
    friend Modular operator - (const Modular &a, const Modular &b) { return Modular(a) -= b; }
    friend Modular operator * (const Modular &a, const Modular &b) { return Modular(a) *= b; }
    friend Modular operator / (const Modular &a, const Modular &b) { return Modular(a) /= b; }
};

// const int Mod = 998244353;
// const int Mod = 1e9 + 9; // 1000000009 
const int Mod = 1e9 + 7; // 1000000007

using Modint = Modular <Mod>;

template <class T> T pow(T a, long long b) {
    T ans = 1, mul = a;
    for (; b; b >>= 1) {
        if(b & 1LL) ans *= mul;
        mul *= mul;
    }
    return ans;
}

const int Max_size = 1e5 + 5;
Modint fact[Max_size + 5], invs[Max_size + 5];

void prepare_Comb() {
    fact[0] = invs[0] = 1;
    for (int i = 1; i <= Max_size; ++i) fact[i] = fact[i - 1] * i;
    invs[Max_size] = fact[Max_size].inv();
    for (int i = Max_size - 1; i >= 1; --i) invs[i] = invs[i + 1] * (i + 1);
}

Modint C(int n, int k) {
    if(n < k || k < 0) return 0;
    return fact[n] * invs[k] * invs[n - k];
}

Modint A(int n, int k) {
    if(n < k || k < 0) return 0;
    return fact[n] * invs[n - k];
}

const int MAX = 2e3 + 5;

int N, M;
Modint dp[2 * MAX];

void you_make_it(void) {
	cin >> N >> M;
	dp[0] = 1;
	for (int i = 0; i < M; ++i) {
		int len = (2 * N - i) / M;
		for (int s = N; s >= 1; --s) {
			for (int j = 1; 2 * j <= len && j <= s; ++j) {
				dp[s] += dp[s - j] * A(len, 2 * j) * C(s, j);
			}
		}
	}
	// for (int i = 0; i <= N; ++i) cout << dp[i] << " "; cout << '\n';

	Modint ans = 0;
	for (int i = 0; i <= N; ++i) ans += dp[i] * (i & 1 ? - 1 : 1) * fact[2 * N - 2 * i] * C(N, i);
	cout << ans;
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    file("nom");
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    prepare_Comb();

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:143:5: note: in expansion of macro 'file'
  143 |     file("nom");
      |     ^~~~
Main.cpp:10:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:143:5: note: in expansion of macro 'file'
  143 |     file("nom");
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Incorrect 2 ms 1116 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Incorrect 2 ms 1116 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Incorrect 2 ms 1116 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Incorrect 2 ms 1116 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Incorrect 2 ms 1116 KB Output isn't correct
7 Halted 0 ms 0 KB -