結果
問題 | No.2668 Trees on Graph Paper |
ユーザー | shobonvip |
提出日時 | 2024-03-08 23:01:30 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 635 ms / 3,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 3,987 ms |
コンパイル使用メモリ | 266,248 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-29 20:31:36 |
合計ジャッジ時間 | 11,510 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include<bits/stdc++.h>using namespace std;//* ATCODER#include<atcoder/all>using namespace atcoder;typedef modint mint;//*//* BOOST MULTIPRECISION#include<boost/multiprecision/cpp_int.hpp>using namespace boost::multiprecision;//*/typedef long long ll;#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)template <typename T> bool chmin(T &a, const T &b) {if (a <= b) return false;a = b;return true;}template <typename T> bool chmax(T &a, const T &b) {if (a >= b) return false;a = b;return true;}template <typename T> T max(vector<T> &a){assert(!a.empty());T ret = a[0];for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);return ret;}template <typename T> T min(vector<T> &a){assert(!a.empty());T ret = a[0];for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);return ret;}template <typename T> T sum(vector<T> &a){T ret = 0;for (int i=0; i<(int)a.size(); i++) ret += a[i];return ret;}int main(){ios_base::sync_with_stdio(false);cin.tie(NULL);int n, m; cin >> n >> m;mint::set_mod(m);mint ans = 1;rep(i,1,2*n){ans *= i;}vector<mint> dp(3);dp[0] = 1;rep(i,0,2*n+4){vector<mint> ndp(3);rep(j,0,3){if (j-1 >= 0){ndp[j-1] += mint(i+1) * dp[j];}ndp[j] += dp[j];if (j+1 < 3){ndp[j+1] += dp[j];}if (j+2 < 3){ndp[j+2] += dp[j];}}dp = ndp;if ((i%2 == 0) && i < 2*n-2){ans *= dp[2];}}cout << ans.val() << '\n';}