結果

問題 No.985 Hadamard
ユーザー chielochielo
提出日時 2020-02-11 15:15:45
言語 C++17(clang Beta)
(clang 13.0.0 + boost 1.81.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,225 bytes
コンパイル時間 1,407 ms
実行使用メモリ 15,964 KB
最終ジャッジ日時 2023-01-06 20:47:32
合計ジャッジ時間 5,620 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
3,516 KB
testcase_01 AC 2 ms
3,600 KB
testcase_02 AC 2 ms
3,532 KB
testcase_03 AC 1 ms
3,456 KB
testcase_04 AC 93 ms
15,864 KB
testcase_05 AC 48 ms
9,648 KB
testcase_06 AC 1 ms
3,632 KB
testcase_07 AC 1 ms
3,600 KB
testcase_08 AC 1 ms
3,612 KB
testcase_09 AC 48 ms
9,640 KB
testcase_10 AC 2 ms
3,652 KB
testcase_11 AC 2 ms
3,460 KB
testcase_12 AC 2 ms
3,612 KB
testcase_13 AC 91 ms
15,864 KB
testcase_14 AC 90 ms
15,792 KB
testcase_15 AC 91 ms
15,876 KB
testcase_16 AC 91 ms
15,852 KB
testcase_17 AC 90 ms
15,872 KB
testcase_18 AC 91 ms
15,796 KB
testcase_19 AC 91 ms
15,792 KB
testcase_20 AC 91 ms
15,788 KB
testcase_21 AC 90 ms
15,796 KB
testcase_22 AC 91 ms
15,964 KB
testcase_23 AC 82 ms
15,860 KB
testcase_24 AC 83 ms
15,728 KB
testcase_25 AC 83 ms
15,784 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