結果

問題 No.2272 多項式乗算 mod 258280327
ユーザー Dmitrii KozyrevDmitrii Kozyrev
提出日時 2023-04-16 04:21:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,620 bytes
コンパイル時間 3,402 ms
コンパイル使用メモリ 285,244 KB
実行使用メモリ 16,096 KB
最終ジャッジ日時 2024-04-19 19:10:04
合計ジャッジ時間 32,157 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,808 ms
14,300 KB
testcase_01 AC 1,798 ms
13,184 KB
testcase_02 AC 1,782 ms
13,184 KB
testcase_03 AC 1,786 ms
13,056 KB
testcase_04 AC 1,813 ms
13,056 KB
testcase_05 AC 1,828 ms
13,056 KB
testcase_06 AC 1,834 ms
12,928 KB
testcase_07 AC 1,798 ms
13,056 KB
testcase_08 AC 1,817 ms
13,056 KB
testcase_09 AC 1,828 ms
13,056 KB
testcase_10 AC 1,833 ms
15,972 KB
testcase_11 AC 1,814 ms
15,836 KB
testcase_12 AC 1,815 ms
14,688 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,803 ms
14,436 KB
testcase_16 AC 1,838 ms
14,044 KB
testcase_17 AC 1,845 ms
14,564 KB
testcase_18 AC 1,790 ms
15,580 KB
testcase_19 AC 1,820 ms
15,452 KB
testcase_20 AC 1,900 ms
15,968 KB
testcase_21 AC 1,808 ms
14,940 KB
testcase_22 AC 1,804 ms
14,940 KB
testcase_23 AC 1,792 ms
15,200 KB
testcase_24 AC 1,804 ms
15,712 KB
testcase_25 AC 1,802 ms
14,820 KB
testcase_26 AC 1,797 ms
15,328 KB
testcase_27 AC 1,836 ms
15,460 KB
testcase_28 AC 1,823 ms
15,588 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma") 
using namespace std;
using ll = long long;

const int mod = 258280327;

namespace {
    template<int n, typename T>
    void mult(const T *__restrict a, const T *__restrict b, T *__restrict res) {
        if (n <= 64) { // if length is small then naive multiplication if faster
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    //res[i + j] += (res[i + j] + (ll)a[i] * b[j]) % mod;
                    (res[i + j] += a[i] * b[j]) %= mod;
                }
            }
        } else {
            // cout << n << endl;
            const int mid = n / 2;
            alignas(64) T btmp[n], E[n] = {};
            auto atmp = btmp + mid;
            for (int i = 0; i < mid; i++) {
                atmp[i] = a[i] + a[i + mid]; // atmp(x) - sum of two halfs a(x)
                //if(atmp[i] >= mod) atmp[i] -= mod;
                btmp[i] = b[i] + b[i + mid]; // btmp(x) - sum of two halfs b(x)
                //if(btmp[i] >= mod) btmp[i] -= mod;
            }
            // cout << "sum" << endl;
            mult<mid>(atmp, btmp, E); // Calculate E(x) = (alow(x) + ahigh(x)) * (blow(x) + bhigh(x))
            // cout << "mult1" << endl;
            mult<mid>(a + 0, b + 0, res); // Calculate rlow(x) = alow(x) * blow(x)
            // cout << "mult2" << endl;
            mult<mid>(a + mid, b + mid, res + n); // Calculate rhigh(x) = ahigh(x) * bhigh(x)
            // cout << "mult3" << endl;
            for (int i = 0; i < mid; i++) { // Then, calculate rmid(x) = E(x) - rlow(x) - rhigh(x) and write in memory
                const auto tmp = res[i + mid];
                res[i + mid] += E[i] - res[i] - res[i + 2 * mid];
                //res[i + mid] %= mod;
                res[i + 2 * mid] += E[i + mid] - tmp - res[i + 3 * mid];
                //res[i + 2 * mid] %= mod;
            }
            // cout << "done" << endl;
        }
    }
}

const int nmax = (1 << 12) * 49;
alignas(64) static ll a[nmax],b[nmax],ret[2 * nmax];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n;
    for(int i = 0;i <= n;++i) {
        cin >> a[i];
        a[i] %= mod;
        //a[i] %= mod;
    }
    cin >> m;
    for(int i = 0;i <= m;++i) {
        cin >> b[i];
        b[i] %= mod;
        //b[i] %= mod;
    }
    mult<nmax>(a, b, ret);
    cout << n + m << endl;
    for(int i = 0;i <= n + m;++i){
        auto x = (ret[i] % mod + mod) % mod;
        cout << x << ' ';
    }
    cout << endl;
    return 0;
}
0