結果

問題 No.2272 多項式乗算 mod 258280327
ユーザー ruthenruthen
提出日時 2023-04-15 01:57:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,126 bytes
コンパイル時間 2,379 ms
コンパイル使用メモリ 205,372 KB
実行使用メモリ 22,340 KB
最終ジャッジ日時 2024-04-18 23:01:38
合計ジャッジ時間 9,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
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 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
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 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 57 ms
5,376 KB
testcase_26 AC 63 ms
5,376 KB
testcase_27 AC 187 ms
5,504 KB
testcase_28 AC 230 ms
5,632 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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>;

#include <atcoder/modint>
using mint = atcoder::static_modint<258280327>;
ostream &operator<<(ostream &os, const mint &p) { return os << p.val(); }

V<mint> convolution(V<mint> &a, V<mint> &b) {
    assert(a.size() == b.size());
    const int n = (int)a.size();
    if (n <= 60) {
        V<mint> c(n + n - 1);
        REP(i, n) REP(j, n) c[i + j] += a[i] * b[j];
        return c;
    }
    const int n2 = (n + 1) / 2;
    V<mint> a0(n2), a1(n2), b0(n2), b1(n2);
    for (int i = 0; i < n2; i++) {
        a0[i] = a[i];
        b0[i] = b[i];
    }
    for (int i = n2; i < n; i++) {
        a1[i - n2] = a[i];
        b1[i - n2] = b[i];
    }
    V<mint> a01(n2), b01(n2);
    REP(i, n2) {
        a01[i] = a0[i] + a1[i];
        b01[i] = b0[i] + b1[i];
    }
    auto c0 = convolution(a0, b0);
    auto c1 = convolution(a1, b1);
    auto c2 = convolution(a01, b01);
    V<mint> c(n2 + n2 + n2 + n2 - 1);
    REP(i, n2 + n2 - 1) {
        c[i] += c0[i];
        c[i + n2] += c2[i] - c0[i] - c1[i];
        c[i + n2 + n2] += c1[i];
    }
    return c;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    N++;
    V<long long> a(N);
    REP(i, N) cin >> a[i];
    int M;
    cin >> M;
    M++;
    V<long long> b(M);
    REP(i, N) 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;
    }
    V<mint> A(N);
    REP(i, N) A[i] = a[i];
    V<mint> B(M);
    REP(i, M) B[i] = b[i];
    int K = max(N, M);
    while (A.size() < K) A.push_back(0);
    while (B.size() < K) B.push_back(0);
    auto C = convolution(A, B);
    show(C);
    while (C.size() > N + M - 1) C.pop_back();
    show(C);
    cout << C.size() - 1 << '\n';
    REP(i, C.size()) cout << C[i] << " \n"[i + 1 == C.size()];
    return 0;
}
0