Submission #509630

#TimeUsernameProblemLanguageResultExecution timeMemory
509630hollwo_pelwNoM (RMI21_nom)C++17
100 / 100
139 ms31820 KiB
/* // is short or still long ??? hollwo_pelw's template(short) // Note : -Dhollwo_pelw_local */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> // #include <ext/rope> using namespace std; // using namespace __gnu_pbds; // using namespace __gnu_cxx; void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){ if (fopen(filein.c_str(), "r")){ freopen(filein.c_str(), "r", stdin); freopen(fileout.c_str(), "w", stdout); #ifdef hollwo_pelw_local freopen(fileerr.c_str(), "w", stderr); #endif } cin.tie(0), cout.tie(0) -> sync_with_stdio(0); } void Hollwo_Pelw(); signed main(){ #ifdef hollwo_pelw_local FAST_IO("input.inp", "output.out", "error.err"); auto start = chrono::steady_clock::now(); #else FAST_IO("hollwo_pelw.inp", "hollwo_pelw.out"); #endif int testcases = 1; // cin >> testcases; for (int test = 1; test <= testcases; test++){ // cout << "Case #" << test << ": "; Hollwo_Pelw(); } #ifdef hollwo_pelw_local auto end = chrono::steady_clock::now(); cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl; #endif return 0; } template<class T> struct mod_int { static constexpr int mod() { return T::mod; } int v; mod_int(long long _v = 0) : v(norm(_v)) {} inline int norm(long long a) { return a < 0 ? a % mod() + mod() : a % mod(); } mod_int neg() const { return v == 0 ? 0 : mod() - v; } template <typename U> explicit operator U() const { return v; } mod_int operator - () const { return neg(); } mod_int operator + () const { return mod_int(*this); } mod_int& operator -- () { if (v == 0) v = mod(); -- v; return *this; } friend mod_int operator -- (mod_int& a, int) { mod_int r = a; --a; return r; } mod_int& operator ++ () { ++ v; if (v == mod()) v = 0; return *this; } friend mod_int operator ++ (mod_int& a, int) { mod_int r = a; ++a; return r; } #define defop(type, op) \ friend inline type operator op (type a, const type &b) { return a op##= b; } \ type& operator op##= (const type &oth) defop(mod_int, +) { if ((v += oth.v) >= mod()) v -= mod(); return *this; } defop(mod_int, -) { if ((v -= oth.v) < 0) v += mod(); return *this; } defop(mod_int, *) { return *this = norm(1ll * v * oth.v); } mod_int pow(long long b) const { mod_int a = *this, r = 1; while (b) { if (b&1) r *= a; b >>= 1; a *= a; } return r; } mod_int inv() const { return pow(mod() - 2); } defop(mod_int, /) { return *this *= oth.inv(); } #undef defop #define compare(op) friend bool operator op \ (const mod_int& lhs, const mod_int& rhs) { return lhs.v op rhs.v; } compare(==) compare(!=) compare(<) compare(<=) compare(>) compare(>=) #undef compare friend std::ostream& operator << (std::ostream& out, const mod_int& n) { return out << int(n); } friend std::istream& operator >> (std::istream& inp, mod_int& n) { long long x; inp >> x; n = mod_int(x); return inp; } }; struct modular { static constexpr int mod = static_cast<int>(1e9 + 7); }; // struct modular { static int mod; }; // int modular::mod; using Mint = mod_int<modular>; const int N = 2005; int n, m, cnt[N]; Mint dp[N][N * 2], fac[N * 2], inv[N * 2]; inline Mint C(int n, int k) { return n < 0 || k > n ? 0 : fac[n] * inv[n - k] * inv[k]; } void Hollwo_Pelw() { fac[0] = 1; for (int i = 1; i < N * 2; i++) fac[i] = fac[i - 1] * i; inv[N * 2 - 1] = fac[N * 2 - 1].inv(); for (int i = N * 2 - 1; i; i--) inv[i - 1] = inv[i] * i; cin >> n >> m; for (int i = 0; i < 2 * n; i++) cnt[i % m] ++; dp[0][0] = 1; for (int i = 0, sum = 0; i < m; i++) { for (int j = 0; j <= sum; j++) if (dp[i][j]) for (int p = 0; p * 2 <= cnt[i]; p ++) dp[i + 1][j + p] += dp[i][j] * C(n - j, p) * fac[cnt[i]] * inv[cnt[i] - p * 2]; sum += cnt[i]; } for (int i = n; ~i; i--) { dp[m][i] *= fac[2 * n - 2 * i]; for (int j = i + 1; j <= n; j++) dp[m][i] -= C(j, i) * dp[m][j]; } cout << dp[m][0]; }

Compilation message (stderr)

Main.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
Main.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...