結果
問題 | No.3145 Astral Parentheses Sequence |
ユーザー |
|
提出日時 | 2025-05-16 21:54:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,065 bytes |
コンパイル時間 | 1,465 ms |
コンパイル使用メモリ | 165,584 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-16 21:54:35 |
合計ジャッジ時間 | 3,567 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,s,n) for (int i = (s); i < (n); ++i) #define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define len(x) (int)(x).size() #define dup(x,y) (((x)+(y)-1)/(y)) #define pb push_back #define eb emplace_back #define Field(T) vector<vector<T>> using namespace std; using ll = long long; using ull = unsigned long long; template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>; using P = pair<int,int>; template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;} int main() { int n, m; cin >> n >> m; if (n % 3 != 0) { cout << 0 << endl; return 0; } n /= 3; vector<ll> a(n+1, 0), b(n+1, 0); a[0] = b[0] = 1; rep(i,1,n+1) { rep(k,0,i) { b[i] += (a[k]*a[i-k-1])%m; b[i] %= m; } rep(k,1,i+1) { a[i] += (b[k]*a[i-k])%m; a[i] %= m; } } cout << a[n] << endl; return 0; }