結果

問題 No.2605 Pickup Parentheses
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-12-04 21:50:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 3,890 ms
コンパイル使用メモリ 193,772 KB
実行使用メモリ 13,300 KB
最終ジャッジ日時 2024-03-20 19:44:38
合計ジャッジ時間 8,786 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 105 ms
7,344 KB
testcase_19 AC 51 ms
6,676 KB
testcase_20 AC 12 ms
6,676 KB
testcase_21 AC 8 ms
6,676 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 97 ms
7,096 KB
testcase_24 AC 12 ms
6,676 KB
testcase_25 AC 130 ms
8,336 KB
testcase_26 AC 138 ms
7,932 KB
testcase_27 AC 86 ms
6,748 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 18 ms
6,676 KB
testcase_30 AC 44 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 89 ms
6,772 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 71 ms
6,676 KB
testcase_38 AC 36 ms
6,676 KB
testcase_39 AC 13 ms
6,676 KB
testcase_40 AC 70 ms
6,676 KB
testcase_41 AC 77 ms
7,284 KB
testcase_42 AC 86 ms
7,320 KB
testcase_43 AC 24 ms
6,676 KB
testcase_44 AC 26 ms
6,676 KB
testcase_45 AC 10 ms
6,676 KB
testcase_46 AC 12 ms
6,676 KB
testcase_47 AC 3 ms
6,676 KB
testcase_48 AC 25 ms
6,676 KB
testcase_49 AC 64 ms
6,676 KB
testcase_50 AC 28 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 42 ms
6,676 KB
testcase_53 AC 55 ms
6,676 KB
testcase_54 AC 32 ms
6,676 KB
testcase_55 AC 49 ms
6,676 KB
testcase_56 AC 14 ms
6,676 KB
testcase_57 AC 2 ms
6,676 KB
testcase_58 AC 240 ms
13,300 KB
testcase_59 AC 110 ms
7,852 KB
testcase_60 AC 138 ms
8,248 KB
testcase_61 AC 123 ms
7,980 KB
testcase_62 AC 138 ms
8,648 KB
testcase_63 AC 129 ms
8,224 KB
testcase_64 AC 148 ms
7,852 KB
testcase_65 AC 117 ms
7,824 KB
testcase_66 AC 213 ms
11,764 KB
testcase_67 AC 129 ms
8,148 KB
testcase_68 AC 31 ms
6,676 KB
testcase_69 AC 2 ms
6,676 KB
testcase_70 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
using ll = long long;
#define REP(i, n) for(ll i=0; i<(n);i++)
#define PER(i, n) for(ll i=n-1; i>=0;i--)

int main() {
  ll n, m;
  cin >> n >> m;

  if (n % 2) {
    cout << 0;
    return 0;
  }

  vector<mint> f(n + 1, 1), rf(n + 1, 1);
  REP(i, n) {
    f[i + 1] = f[i] * (i + 1);
    rf[i + 1] = mint(1) / f[i + 1];
  }

  vector<vector<mint>> dps={{1}};
  REP(i, m) {
    ll l, r;
    cin >> l >> r;
    if((r-l)%2){
    	ll d=(r-l+1)/2;
    	vector<mint> add(d+1);
    	add[0]=1;
    	add[d]=-f[d*2]*rf[d]*rf[d]/(d+1);
    	dps.push_back(add);
    }
  }

  while(dps.size()>1){
  	vector<vector<mint>> ndps;
  	REP(i,dps.size() / 2){
  		ndps.push_back(convolution(dps[i*2],dps[i*2+1]));
  	}
  	if(dps.size()%2){
  		ndps.push_back(dps.back());
  	}
  	swap(dps,ndps);
  }

  mint ans = 0;
  REP(i, dps[0].size()) {
    ans += dps[0][i] * f[n - i * 2] * rf[n / 2 - i] * rf[n / 2 - i] / (n / 2 - i + 1);
  }
  cout << ans.val();

  return 0;
}
0