結果

問題 No.985 Hadamard
ユーザー risujirohrisujiroh
提出日時 2020-02-11 22:57:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,761 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 172,520 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-04-08 16:42:27
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_04 AC 85 ms
7,424 KB
testcase_05 AC 43 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 44 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 82 ms
7,424 KB
testcase_14 AC 82 ms
7,424 KB
testcase_15 AC 82 ms
7,424 KB
testcase_16 AC 82 ms
7,424 KB
testcase_17 AC 82 ms
7,424 KB
testcase_18 AC 84 ms
7,424 KB
testcase_19 AC 85 ms
7,424 KB
testcase_20 AC 86 ms
7,424 KB
testcase_21 AC 85 ms
7,424 KB
testcase_22 AC 84 ms
7,424 KB
testcase_23 AC 73 ms
7,424 KB
testcase_24 AC 73 ms
7,424 KB
testcase_25 AC 73 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  unsigned v;
  modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; }
  m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; }
  m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; }
  m& operator/=(m r) { return *this *= power(r, M - 2); }
  friend m operator+(m l, m r) { return l += r; }
  friend m operator-(m l, m r) { return l -= r; }
  friend m operator*(m l, m r) { return l *= r; }
  friend m operator/(m l, m r) { return l /= r; }
  friend bool operator==(m l, m r) { return l.v == r.v; }
};

constexpr long long mod = 998244353;
using mint = modular<mod>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> c(1 << n);
  for (auto&& e : c) {
    cin >> e;
  }
  vector<mint> l(1 << n), h(1 << n);
  for (int i = 0; i < 1 << n; ++i) {
    int li, hi;
    cin >> li >> hi;
    l[i] = li, h[i] = hi;
  }
  for (int i = 0; i < n; ++i) {
    for (int bt = 0; bt < 1 << n; ++bt) {
      if (bt >> i & 1) {
        auto x = c[bt ^ 1 << i], y = c[bt];
        c[bt ^ 1 << i] = x + y;
        c[bt] = x - y;
      }
    }
  }
  mint res;
  for (int i = 0; i < 1 << n; ++i) {
    if (c[i] > 0) {
      res += c[i] * h[i];
    }
    if (c[i] < 0) {
      res += c[i] * l[i];
    }
  }
  res /= power(mint(2), n);
  cout << res.v << '\n';
}
0