結果

問題 No.2605 Pickup Parentheses
ユーザー ぷらぷら
提出日時 2024-01-12 21:54:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,136 ms / 2,000 ms
コード長 2,993 bytes
コンパイル時間 4,223 ms
コンパイル使用メモリ 216,196 KB
実行使用メモリ 25,900 KB
最終ジャッジ日時 2024-03-20 19:47:19
合計ジャッジ時間 21,635 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,276 KB
testcase_01 AC 5 ms
8,276 KB
testcase_02 AC 5 ms
8,276 KB
testcase_03 AC 9 ms
8,536 KB
testcase_04 AC 10 ms
8,536 KB
testcase_05 AC 12 ms
8,664 KB
testcase_06 AC 15 ms
8,792 KB
testcase_07 AC 12 ms
8,664 KB
testcase_08 AC 16 ms
8,792 KB
testcase_09 AC 8 ms
8,404 KB
testcase_10 AC 12 ms
8,664 KB
testcase_11 AC 10 ms
8,536 KB
testcase_12 AC 7 ms
8,404 KB
testcase_13 AC 6 ms
8,276 KB
testcase_14 AC 7 ms
8,404 KB
testcase_15 AC 9 ms
8,532 KB
testcase_16 AC 7 ms
8,404 KB
testcase_17 AC 8 ms
8,404 KB
testcase_18 AC 623 ms
18,688 KB
testcase_19 AC 270 ms
13,692 KB
testcase_20 AC 53 ms
9,304 KB
testcase_21 AC 34 ms
9,048 KB
testcase_22 AC 10 ms
8,660 KB
testcase_23 AC 550 ms
18,396 KB
testcase_24 AC 49 ms
9,304 KB
testcase_25 AC 755 ms
21,548 KB
testcase_26 AC 798 ms
21,828 KB
testcase_27 AC 468 ms
17,884 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 64 ms
9,688 KB
testcase_30 AC 163 ms
11,748 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 376 ms
15,544 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 3 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 317 ms
13,976 KB
testcase_38 AC 119 ms
11,652 KB
testcase_39 AC 39 ms
9,248 KB
testcase_40 AC 316 ms
15,516 KB
testcase_41 AC 267 ms
15,268 KB
testcase_42 AC 416 ms
16,308 KB
testcase_43 AC 74 ms
10,460 KB
testcase_44 AC 68 ms
10,492 KB
testcase_45 AC 6 ms
8,404 KB
testcase_46 AC 26 ms
9,348 KB
testcase_47 AC 5 ms
8,276 KB
testcase_48 AC 7 ms
8,532 KB
testcase_49 AC 240 ms
13,668 KB
testcase_50 AC 84 ms
10,080 KB
testcase_51 AC 3 ms
6,676 KB
testcase_52 AC 137 ms
11,480 KB
testcase_53 AC 195 ms
12,628 KB
testcase_54 AC 101 ms
10,796 KB
testcase_55 AC 163 ms
11,756 KB
testcase_56 AC 37 ms
9,300 KB
testcase_57 AC 3 ms
6,676 KB
testcase_58 AC 1,136 ms
24,956 KB
testcase_59 AC 592 ms
16,896 KB
testcase_60 AC 738 ms
20,500 KB
testcase_61 AC 676 ms
20,848 KB
testcase_62 AC 790 ms
20,292 KB
testcase_63 AC 734 ms
21,972 KB
testcase_64 AC 809 ms
21,292 KB
testcase_65 AC 633 ms
19,088 KB
testcase_66 AC 1,082 ms
25,900 KB
testcase_67 AC 713 ms
21,324 KB
testcase_68 AC 5 ms
8,148 KB
testcase_69 AC 2 ms
6,676 KB
testcase_70 AC 6 ms
8,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

constexpr int mod = 998244353;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long choose(int n,int k) {
    if(n < 0 || k < 0) return 0;
    if(n == 0) return 1;
    return COM(n+k-1,k-1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    if(N%2) {
        cout << 0 << "\n";
        return 0;
    }
    COMinit();
    vector<pair<vector<int>,vector<int>>>tmp;
    for(int i = 0; i < M; i++) {
        int L,R;
        cin >> L >> R;
        L--;
        if((R-L)%2) continue;
        vector<int>a(R-L+1),b(R-L+1);
        a[0] = 1;
        b[R-L] = (COM(R-L,(R-L)/2)+mod-COM(R-L,(R-L)/2+1))%mod;
        tmp.push_back({a,b});
    }
    while(tmp.size() > 1) {
        vector<pair<vector<int>,vector<int>>>nxt;
        for(int i = 0; i < tmp.size(); i += 2) {
            if(i+1 == tmp.size()) {
                nxt.push_back(tmp[i]);
            }
            else {
                auto a1 = convolution(tmp[i].first,tmp[i+1].first);
                auto a2 = convolution(tmp[i].second,tmp[i+1].second);
                auto b1 = convolution(tmp[i].first,tmp[i+1].second);
                auto b2 = convolution(tmp[i].second,tmp[i+1].first);
                for(int i = 0; i < a1.size(); i++) {
                    a1[i] += a2[i];
                    if(a1[i] >= mod) a1[i] -= mod;
                    b1[i] += b2[i];
                    if(b1[i] >= mod) b1[i] -= mod;
                }
                nxt.push_back({a1,b1});
            }
        }
        tmp = nxt;
    }
    if(tmp.empty()) {
        cout << (COM(N,N/2)+mod-COM(N,N/2+1))%mod << "\n";
        return 0;
    }
    int ans = 0;
    for(int i = 0; i < tmp[0].first.size(); i += 2) {
        ans += (COM(N-i,(N-i)/2)+mod-COM(N-i,(N-i)/2+1))%mod*tmp[0].first[i]%mod;
        if(ans >= mod) ans -= mod;
        ans += mod-(COM(N-i,(N-i)/2)+mod-COM(N-i,(N-i)/2+1))%mod*tmp[0].second[i]%mod;
        if(ans >= mod) ans -= mod;
    }
    cout << ans << "\n";
}
0