結果
| 問題 |
No.3145 Astral Parentheses Sequence
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2025-05-16 22:22:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 722 bytes |
| コンパイル時間 | 1,840 ms |
| コンパイル使用メモリ | 198,496 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-16 22:22:15 |
| 合計ジャッジ時間 | 3,432 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define all(p) p.begin(), p.end()
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#include<atcoder/modint>
using mint = atcoder::modint;
int main(){
int N, M;
cin >> N >> M;
mint::set_mod(M);
if (N % 3){
cout << "0\n";
return 0;
}
N /= 3;
vector<mint> dp(1 + N), A(1 + N), B(1 + N);
dp[0] = 1;
A[0] = 1;
B[0] = 1;
rep(i, 1, N + 1){
rep(j, 0, i){
dp[i] += B[j] * dp[i - 1 - j];
}
// B[i] を求める
rep(j, 0, i){
A[i] += A[j] * B[i - j - 1];
B[i] += (A[j] + B[j]) * B[i - j - 1];
}
}
cout << dp[N].val() << "\n";
}
potato167