結果

問題 No.2605 Pickup Parentheses
ユーザー KudeKude
提出日時 2024-01-12 23:17:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 2,265 bytes
コンパイル時間 3,636 ms
コンパイル使用メモリ 288,200 KB
実行使用メモリ 18,776 KB
最終ジャッジ日時 2024-03-20 19:50:12
合計ジャッジ時間 11,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
11,332 KB
testcase_01 AC 14 ms
11,332 KB
testcase_02 AC 13 ms
11,332 KB
testcase_03 AC 15 ms
11,460 KB
testcase_04 AC 15 ms
11,460 KB
testcase_05 AC 15 ms
11,460 KB
testcase_06 AC 17 ms
11,460 KB
testcase_07 AC 15 ms
11,460 KB
testcase_08 AC 16 ms
11,588 KB
testcase_09 AC 15 ms
11,332 KB
testcase_10 AC 16 ms
11,460 KB
testcase_11 AC 15 ms
11,460 KB
testcase_12 AC 14 ms
11,332 KB
testcase_13 AC 14 ms
11,332 KB
testcase_14 AC 15 ms
11,460 KB
testcase_15 AC 16 ms
11,460 KB
testcase_16 AC 14 ms
11,332 KB
testcase_17 AC 15 ms
11,460 KB
testcase_18 AC 144 ms
15,808 KB
testcase_19 AC 76 ms
13,720 KB
testcase_20 AC 25 ms
11,716 KB
testcase_21 AC 21 ms
11,716 KB
testcase_22 AC 16 ms
11,588 KB
testcase_23 AC 143 ms
15,312 KB
testcase_24 AC 25 ms
11,844 KB
testcase_25 AC 178 ms
16,788 KB
testcase_26 AC 188 ms
16,736 KB
testcase_27 AC 123 ms
15,648 KB
testcase_28 AC 194 ms
16,948 KB
testcase_29 AC 43 ms
12,484 KB
testcase_30 AC 95 ms
13,904 KB
testcase_31 AC 99 ms
14,128 KB
testcase_32 AC 48 ms
12,656 KB
testcase_33 AC 198 ms
16,540 KB
testcase_34 AC 184 ms
17,060 KB
testcase_35 AC 128 ms
15,492 KB
testcase_36 AC 155 ms
16,516 KB
testcase_37 AC 167 ms
16,772 KB
testcase_38 AC 42 ms
13,016 KB
testcase_39 AC 22 ms
11,844 KB
testcase_40 AC 84 ms
15,564 KB
testcase_41 AC 81 ms
15,296 KB
testcase_42 AC 111 ms
15,904 KB
testcase_43 AC 30 ms
12,288 KB
testcase_44 AC 30 ms
12,440 KB
testcase_45 AC 14 ms
11,332 KB
testcase_46 AC 19 ms
11,844 KB
testcase_47 AC 14 ms
11,332 KB
testcase_48 AC 54 ms
14,792 KB
testcase_49 AC 125 ms
15,884 KB
testcase_50 AC 56 ms
13,532 KB
testcase_51 AC 103 ms
15,780 KB
testcase_52 AC 72 ms
14,104 KB
testcase_53 AC 92 ms
15,936 KB
testcase_54 AC 55 ms
13,552 KB
testcase_55 AC 87 ms
15,528 KB
testcase_56 AC 30 ms
12,228 KB
testcase_57 AC 106 ms
16,412 KB
testcase_58 AC 288 ms
18,776 KB
testcase_59 AC 146 ms
16,124 KB
testcase_60 AC 179 ms
16,624 KB
testcase_61 AC 169 ms
15,836 KB
testcase_62 AC 198 ms
17,052 KB
testcase_63 AC 180 ms
16,380 KB
testcase_64 AC 205 ms
17,648 KB
testcase_65 AC 157 ms
16,488 KB
testcase_66 AC 259 ms
17,744 KB
testcase_67 AC 174 ms
15,884 KB
testcase_68 AC 14 ms
11,332 KB
testcase_69 AC 14 ms
11,332 KB
testcase_70 AC 14 ms
11,332 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:49:6: warning: '{anonymous}::mint {anonymous}::perm(int, int)' defined but not used [-Wunused-function]
   49 | mint perm(int n, int k) {
      |      ^~~~
main.cpp:48:6: warning: '{anonymous}::mint {anonymous}::fact(int)' defined but not used [-Wunused-function]
   48 | mint fact(int n) {return Fact[n];}
      |      ^~~~
main.cpp:44:6: warning: '{anonymous}::mint {anonymous}::icomb(int, int)' defined but not used [-Wunused-function]
   44 | mint icomb(int n, int k) {
      |      ^~~~~

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

constexpr int FACT_SIZE = 1000000;
mint Fact[FACT_SIZE + 1];
mint iFact[FACT_SIZE + 1];
const auto fact_init = [] {
    Fact[0] = mint::raw(1);
    for(int i = 1; i <= FACT_SIZE; ++i) {
        Fact[i] = Fact[i-1] * i;
    }
    iFact[FACT_SIZE] = Fact[FACT_SIZE].inv();
    for(int i = FACT_SIZE; i; --i) {
        iFact[i-1] = iFact[i] * i;
    }
    return false;
}();

mint comb(int n, int k) {
    if (k == 0) return mint::raw(1);
    assert(n >= 0 && k >= 0);
    if (k > n) return mint::raw(0);
    return Fact[n] * iFact[n - k] * iFact[k];
}

mint icomb(int n, int k) {
    return iFact[n] * Fact[n - k] * Fact[k];
}

mint fact(int n) {return Fact[n];}
mint perm(int n, int k) {
    assert(0 <= n);
    return Fact[n] * iFact[n - k];
}

mint f(int len) {
  if (len % 2) return 0;
  if (len == 0) return 1;
  int n = len / 2;
  return comb(2 * n, n) - comb(2 * n, n - 1);
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  queue<vector<mint>> q;
  q.push({1});
  rep(_, m) {
    int l, r;
    cin >> l >> r;
    l--;
    vector<mint> g(r - l + 1);
    g[0] = 1;
    g[r - l] = -f(r - l);
    q.emplace(move(g));
  }
  while (q.size() >= 2) {
    auto f = move(q.front()); q.pop();
    auto g = move(q.front()); q.pop();
    q.emplace(convolution(f, g));
  }
  auto h = move(q.front()); q.pop();
  mint ans;
  for (int i = 0; mint v : h) {
    ans += f(n - i) * v;
    // cout << i << ' ' << v.val() << endl;
    i++;
  }
  cout << ans.val() << '\n';
}
0