結果

問題 No.985 Hadamard
ユーザー chielochielo
提出日時 2020-02-11 15:15:45
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,225 bytes
コンパイル時間 2,555 ms
コンパイル使用メモリ 132,712 KB
実行使用メモリ 15,988 KB
最終ジャッジ日時 2023-08-20 13:53:21
合計ジャッジ時間 7,312 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,920 KB
testcase_01 AC 3 ms
13,860 KB
testcase_02 AC 3 ms
13,916 KB
testcase_03 AC 3 ms
13,868 KB
testcase_04 AC 82 ms
15,936 KB
testcase_05 AC 43 ms
14,876 KB
testcase_06 AC 3 ms
13,984 KB
testcase_07 AC 4 ms
13,920 KB
testcase_08 AC 4 ms
13,832 KB
testcase_09 AC 43 ms
14,828 KB
testcase_10 AC 3 ms
13,808 KB
testcase_11 AC 4 ms
13,924 KB
testcase_12 AC 4 ms
13,872 KB
testcase_13 AC 79 ms
15,964 KB
testcase_14 AC 80 ms
15,988 KB
testcase_15 AC 81 ms
15,920 KB
testcase_16 AC 84 ms
15,988 KB
testcase_17 AC 80 ms
15,848 KB
testcase_18 AC 81 ms
15,900 KB
testcase_19 AC 82 ms
15,932 KB
testcase_20 AC 82 ms
15,940 KB
testcase_21 AC 82 ms
15,988 KB
testcase_22 AC 83 ms
15,848 KB
testcase_23 AC 78 ms
15,844 KB
testcase_24 AC 74 ms
15,964 KB
testcase_25 AC 74 ms
15,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

const int maxn = 1 << 18;
typedef long long ll;
const ll mo = 998244353;

int n;
ll c[maxn], d[maxn], l[maxn], h[maxn], b[maxn], a[maxn];

ll mpow(ll u, ll k) {
    ll ans = 1;
    for(; k > 0; k >>= 1, u = u * u % mo) {
        if(k & 1) {
            ans = ans * u % mo;
        }
    }
    return ans;
}

void fwt(const ll *u, ll *v) {
    memcpy(v, u, sizeof(*u) * n);
    for(int d = 1; d < n; d *= 2)
    for(int i = 0; i < n; i += d * 2)
    for(int j = 0; j < d; ++j) {
        auto ui = v[i + j], uj = v[i + j + d];
        auto &vi = v[i + j], &vj = v[i + j + d];
        vi = (ui + uj);
        vj = (ui - uj);
    }
}

int main() {
    scanf("%d", &n);
    n = 1 << n;
    for(int i = 0; i < n; ++i) {
        scanf("%lld", c + i);
    }
    for(int i = 0; i < n; ++i) {
        scanf("%lld%lld", l + i, h + i);
    }
    fwt(c, d);
    for(int i = 0; i < n; ++i) {
        if(d[i] >= 0)
            b[i] = h[i];
        else
            b[i] = l[i];
    }
    fwt(b, a);
    ll ans = 0ll;
    for(int i = 0; i < n; ++i)
        ans = (ans + (a[i] % mo) * (c[i] % mo) % mo) % mo;
    ans = ans * mpow(n, mo - 2) % mo;
    ans = (ans + mo) % mo;
    printf("%lld\n", ans);
    return 0;
}
0