結果

問題 No.3145 Astral Parentheses Sequence
ユーザー Cafe1942
提出日時 2025-05-16 22:12:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,901 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 114,700 KB
実行使用メモリ 334,628 KB
最終ジャッジ日時 2025-05-16 22:13:03
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other -- * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using ll = long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }
/*
int A[150000];

int rec(int L, int R, int B, int op) {
    if (L == R) {
        return op ^ A[L];
    }
    if (((A[L] >> B) & 1) == ((A[R] >> B) & 1)) {
        return rec(L, R, B - 1, ((A[L] >> B) & 1));
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    set<int>S;
    while (N--) {
        int X;
        cin >> X;
        S.insert(X);
    }
    N = S.size();
    int j = 0;
    for (auto itr = S.begin();itr != S.end();itr++) {
        A[j++] = *itr;
    }
    cout << rec(0, N - 1, 29, 0);
    return 0;
}
*/

int main() {
    int N, M;
    cin >> N >> M;
    if (N % 3 != 0) {
        cout << 0;
        return 0;
    }
    //ああ、Mにより、埋め込み回避理解です。
    map<pair<pair<int, int>, pair<int, int>>, int>dp;
    dp[{{0,0},{0,2}}] = 1;
    for (int i = 1;i <= N / 3;i++) {
        for (int j = 0;j <= i;j++) {
            for (int k = 0;k <= j;k++) {
                if (i != 0)dp[{ {i, j}, { k,0 }}] = ((dp[{ {i - 1, j}, { k,0 }}] + dp[{ {i - 1, j}, { k,1 }}]) % M + dp[{ {i - 1, j}, { k,2 }}]) % M;
                if (j != 0)dp[{ {i, j}, { k,1 }}] = (dp[{ {i, j - 1}, { k,0 }}] + dp[{ {i, j - 1}, { k,2 }}]) % M;
                if (k != 0)dp[{ {i, j}, { k,2 }}] = (dp[{ {i, j}, { k - 1,1 }}] + dp[{ {i, j}, { k - 1,2 }}]) % M;
            }
        }
    }
    cout << dp[{ {N/3, N/3}, { N/3,2 }}];
}
0