結果
| 問題 |
No.2668 Trees on Graph Paper
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2024-03-08 22:30:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,861 bytes |
| コンパイル時間 | 2,892 ms |
| コンパイル使用メモリ | 251,784 KB |
| 実行使用メモリ | 27,720 KB |
| 最終ジャッジ日時 | 2024-09-29 20:00:06 |
| 合計ジャッジ時間 | 10,330 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 TLE * 1 -- * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
#include <atcoder/modint>
int main() {
int n, m; cin >> n >> m;
atcoder::modint::set_mod(m);
vector<atcoder::modint> dp1(n + 1, 0);
dp1[1] = dp1[2] = 1;
array<array<atcoder::modint, 4>, 4> dp2{};
FOR(a, 1, 3) REP(b, a + 1) ++dp2[a][b];
FOR(i, 3, n + 1) {
FOR(x, 1, 4) for (int y = 0; y <= x && y <= 2; ++y) {
if (dp2[x][y] == 0) continue;
for (int a = 0; a <= 1 && a <= y; ++a) {
dp1[i] += dp1[i - 1] * dp2[x][y] * (x == 1 || y == 1 || a == 1 ? 1 : i * 2 - 4);
}
}
array<array<atcoder::modint, 4>, 4> nxt{};
FOR(x, 3, 6) for (int y = 2; y <= x && y <= 4; ++y) {
if (dp2[x - 2][y - 2] == 0) continue;
for (int a = 1; a <= y && a <= 3; ++a) for (int b = 0; b <= a && b <= 2; ++b) {
nxt[a][b] += dp2[x - 2][y - 2] * (x == 3 || y == 3 || a == 3 ? 1 : i * 2 - 4) * (y == 2 || a == 2 || b == 2 ? 1 : i * 2 - 3);
}
}
dp2.swap(nxt);
}
atcoder::modint ans = dp1[n];
FOR(i, 1, n * 2) ans *= i;
cout << ans.val() << '\n';
return 0;
}
emthrm