結果

問題 No.2272 多項式乗算 mod 258280327
ユーザー ruthenruthen
提出日時 2023-04-17 20:04:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,242 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 205,748 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-04-20 22:39:07
合計ジャッジ時間 7,872 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 971 ms
22,152 KB
testcase_31 AC 894 ms
22,400 KB
testcase_32 AC 1,023 ms
22,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif

#define REP(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

constexpr int P = 258280327;

void convolution(long long *a, long long *b, const int n, long long *c) {
    if (n <= 120) {
        REP(i, n) REP(j, n) c[i + j] += a[i] * b[j];
        REP(i, n + n - 1) c[i] %= P;
        return;
    }
    const int n0 = (n + 1) / 2;
    const int n1 = n - n0;
    long long *a0 = a, *b0 = b, *a1 = a + n0, *b1 = b + n0;
    long long a01[n0] = {}, b01[n0] = {};
    REP(i, n0) {
        a01[i] = a0[i];
        b01[i] = b0[i];
    }
    REP(i, n1) {
        a01[i] += a1[i];
        b01[i] += b1[i];
        if (a01[i] >= P) a01[i] -= P;
        if (b01[i] >= P) b01[i] -= P;
    }
    long long c0[n0 + n0 - 1] = {}, c1[n1 + n1 - 1] = {}, c2[n0 + n0 - 1] = {};
    convolution(a0, b0, n0, c0);
    convolution(a1, b1, n1, c1);
    convolution(a01, b01, n0, c2);
    REP(i, n0 + n0 - 1) c[i] += c0[i];
    REP(i, n1 + n1 - 1) c[i + n0 + n0] += c1[i];
    REP(i, n0 + n0 - 1) {
        c[i + n0] += c2[i];
        if (c[i + n0] >= P) c[i + n0] -= P;
        c[i + n0] -= c0[i];
        if (c[i + n0] < 0) c[i + n0] += P;
    }
    REP(i, n1 + n1 - 1) {
        c[i + n0] -= c1[i];
        if (c[i + n0] < 0) c[i + n0] += P;
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    constexpr int K = 200005;
    long long a[K], b[K];
    int N;
    cin >> N;
    N++;
    REP(i, N) cin >> a[i];
    int M;
    cin >> M;
    M++;
    REP(i, M) cin >> b[i];
    if (N == 1 and a[0] == 0) {
        cout << 0 << '\n';
        cout << 0 << '\n';
        return 0;
    }
    if (M == 1 and b[0] == 0) {
        cout << 0 << '\n';
        cout << 0 << '\n';
        return 0;
    }
    REP(i, N) a[i] %= P;
    REP(i, M) b[i] %= P;
    int L = max(N, M);
    while (N < L) a[N++] = 0;
    while (M < L) b[M++] = 0;
    long long c[L + L] = {};
    convolution(a, b, L, c);
    cout << N + M - 2 << '\n';
    REP(i, N + M - 1) cout << c[i] << " \n"[i + 1 == N + M - 1];
    return 0;
}
0