답안 #200859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200859 2020-02-08T10:23:53 Z jh05013 씽크스몰 (kriii3_TT) C++17
30 / 30
2139 ms 196088 KB
#include <bits/stdc++.h>
#define sz(X) (int)((X).size())
#define entire(X) X.begin(),X.end()
using namespace std; typedef long long ll;
void OJize(){cin.tie(NULL);ios_base::sync_with_stdio(false);}

const double PI = acos(-1);
typedef complex<double> CD;
typedef vector<CD> VCD;
typedef vector<ll> poly;
void FFT(VCD &A, bool inv){
    int n = A.size();
    for(int i=1, j=0; i<n; i++){
        for(int k=n>>1; (j^=k)<k; k>>= 1);
        if(i < j) swap(A[i], A[j]);
    }
    double ang = 2*PI / n * (inv? -1:1);
    VCD roots(n/2);
    for(int i=0; i<n/2; i++)
        roots[i] = CD(cos(ang*i), sin(ang*i));
    for(int i=2; i<=n; i<<= 1){
        int step = n/i;
        for(int j=0; j<n; j+=i) for(int k=0; k<i/2; k++){
            CD u = A[j+k], v = A[j+k+i/2] * roots[step*k];
            A[j+k] = u+v, A[j+k+i/2] = u-v;
        }
    }
    if(inv) for(int i=0; i<n; i++) A[i]/= n;
}

/* Kriiicon Thinksmall: precise multiplication */
poly thinksmall(poly X, poly Y, ll MOD = 0){
    int N = 2; while(N < sz(X)+sz(Y)) N<<= 1;
    VCD A(N), B(N), AR(N), BR(N);
    
    for(int i=0; i<sz(X); i++) A[i] = CD(X[i]>>15, X[i]&32767);
    for(int i=0; i<sz(Y); i++) B[i] = CD(Y[i]>>15, Y[i]&32767);
    FFT(A, 0); FFT(B, 0);
    for(int i=0; i<N; i++){
        int j = i? N-i : i;
        CD f1 = (A[i] + conj(A[j])) / CD(2, 0),
           f2 = (A[i] - conj(A[j])) / CD(0, 2),
           f3 = (B[i] + conj(B[j])) / CD(2, 0),
           f4 = (B[i] - conj(B[j])) / CD(0, 2);
        AR[i] = f1 * (f3 + f4 * CD(0, 1));
        BR[i] = f2 * (f3 + f4 * CD(0, 1));
    }
    FFT(AR, 1); FFT(BR, 1);
    vector<ll> ans;
    for(int i=0; i<N; i++){
        ll a = (ll)round(AR[i].real()),
           b = (ll)round(AR[i].imag()) + (ll)round(BR[i].real()),
           c = (ll)round(BR[i].imag());
        if(MOD) a%= MOD, b%= MOD, c%= MOD;
        ll res = (a<<30) + (b<<15) + c;
        if(MOD) res%= MOD, res+= MOD, res%= MOD;
        ans.push_back(res);
    }
    return ans;
}

int main(){OJize();
    int n, m; cin>>n>>m;
    poly X(n+1), Y(m+1);
    for(int i=0; i<=n; i++) cin>>X[i];
    for(int i=0; i<=m; i++) cin>>Y[i];
    ll ans = 0;
    for(ll x: thinksmall(X, Y)) ans^= x;
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 408 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3316 KB Output is correct
2 Correct 65 ms 12144 KB Output is correct
3 Correct 67 ms 12528 KB Output is correct
4 Correct 148 ms 23536 KB Output is correct
5 Correct 148 ms 23920 KB Output is correct
6 Correct 142 ms 23792 KB Output is correct
7 Correct 141 ms 24176 KB Output is correct
8 Correct 145 ms 24176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 46248 KB Output is correct
2 Correct 915 ms 91364 KB Output is correct
3 Correct 917 ms 93156 KB Output is correct
4 Correct 2036 ms 191000 KB Output is correct
5 Correct 2019 ms 187912 KB Output is correct
6 Correct 2064 ms 194056 KB Output is correct
7 Correct 2139 ms 196088 KB Output is correct
8 Correct 2094 ms 195872 KB Output is correct