Submission #25629426
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
mint fac[1000],facinv[1000];
mint mycom(int a,int b){
if(a-b<0 || b<0)return 0;
return fac[a]*facinv[b]*facinv[a-b];
}
int n,m;
vector<vector<int>> g;
mint dp[401][401],dp2[401][401];
bool al_dp[401][401],al_dp2[401][401];
mint calc_dp(int i,int j);
mint calc_dp2(int i,int j);
mint calc_dp(int i,int j){
if(al_dp[i][j])return dp[i][j];
if(i==j)return 1;
if(i>j)return 0;
if((j-i)&1)return 0;
mint ans=0;
for(int l=i;l<j;l++){
ans+=calc_dp(i,l)*mycom((j-i-2)/2,(l-i)/2)*calc_dp2(l,j);
}
al_dp[i][j]=true;
return dp[i][j]=ans;
}
mint calc_dp2(int i,int j){
if(al_dp2[i][j])return dp2[i][j];
mint ans=0;
for(int r:g[i])if(r<j){
ans+=calc_dp(i+1,r)*calc_dp(r+1,j)*mycom((j-i-2)/2,(j-r-1)/2);
}
al_dp2[i][j]=true;
return dp2[i][j]=ans;
}
int main(){
fac[0]=facinv[0]=1;
for(int i=0;i<999;i++){
fac[i+1]=fac[i]*(i+1);
facinv[i+1]=facinv[i]/(i+1);
}
cin >> n >> m;
n*=2;
g.resize(n);
while(m--){
int a,b;
cin >> a >> b;
a--,b--;
g[a].emplace_back(b);
}
cout << calc_dp(0,n).val() << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Make Pair |
| User | logx |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1327 Byte |
| Status | AC |
| Exec Time | 259 ms |
| Memory | 5688 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt, example_02.txt |
| All | example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 9 ms | 4808 KiB |
| example_01.txt | AC | 5 ms | 4808 KiB |
| example_02.txt | AC | 2 ms | 4812 KiB |
| hand_00.txt | AC | 259 ms | 5676 KiB |
| hand_01.txt | AC | 143 ms | 5444 KiB |
| hand_02.txt | AC | 6 ms | 4868 KiB |
| hand_03.txt | AC | 37 ms | 5176 KiB |
| hand_04.txt | AC | 45 ms | 5172 KiB |
| hand_05.txt | AC | 4 ms | 4780 KiB |
| hand_06.txt | AC | 5 ms | 4812 KiB |
| random_00.txt | AC | 21 ms | 4916 KiB |
| random_01.txt | AC | 22 ms | 5148 KiB |
| random_02.txt | AC | 20 ms | 5028 KiB |
| random_03.txt | AC | 129 ms | 5400 KiB |
| random_04.txt | AC | 215 ms | 5688 KiB |
| random_05.txt | AC | 10 ms | 4768 KiB |
| random_06.txt | AC | 110 ms | 5308 KiB |
| random_07.txt | AC | 196 ms | 5452 KiB |
| random_08.txt | AC | 210 ms | 5496 KiB |
| random_09.txt | AC | 92 ms | 5268 KiB |
| random_10.txt | AC | 10 ms | 4660 KiB |
| random_11.txt | AC | 142 ms | 5384 KiB |
| random_12.txt | AC | 79 ms | 5100 KiB |
| random_13.txt | AC | 111 ms | 5276 KiB |
| random_14.txt | AC | 114 ms | 5304 KiB |
| random_15.txt | AC | 5 ms | 4756 KiB |
| random_16.txt | AC | 78 ms | 5192 KiB |
| random_17.txt | AC | 71 ms | 5180 KiB |