Submission #421941


Source Code Expand

#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
    template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

typedef double Real;
typedef complex<Real> Complex;

Real const PI = acos(-1);

namespace FastFourierTransform {
    Complex z_[1<<19];
    Complex * z = z_+(1<<18);
    int len;
    void FastFourierTransform(vector<Complex> & f, int inv = 0){
        int n = f.size();
        if(n==1) return;
        vector<Complex> f0(n>>1), f1(n>>1);
        rep(i,n>>1) f0[i] = f[i<<1], f1[i] = f[i<<1|1];
        FastFourierTransform(f0,inv);
        FastFourierTransform(f1,inv);
        int k = len/n, m = n/2-1;
        rep(i,n) f[i] = f0[i&m] + z[inv ? -k*i : k*i] * f1[i&m];
        return;
    }

    vector<Complex> Convolution(vector<Complex> g, vector<Complex> h){
        int n_ = max(g.size(), h.size());
        int n = 1;
        while(n < n_) n<<=1;
        g.resize(n);
        h.resize(n);
        len = n+1;
        rep(i,len) z[i] = polar<Real>(1,2*PI/n*i), z[-i] = conj(z[i]);
        FastFourierTransform(g);
        FastFourierTransform(h);
        vector<Complex> f(n);
        rep(i,n) f[i] = g[i]*h[i];
        FastFourierTransform(f,1);
        rep(i,n) f[i] /= n;
        return f;
    }
}

signed main(){
    int n;
    scanf("%d",&n);
    vector<Complex> g(n*2+1), h(n*2+1);
    rep(i,n){
        int a,b;
        scanf("%d%d",&a,&b);
        g[i+1] = a, h[i+1] = b;
    }
    vector<Complex> f = FastFourierTransform::Convolution(g,h);
    for(int i=1;i<=n*2;i++) printf("%d\n",(int)(f[i].real()+0.5));
}

Submission Info

Submission Time
Task C - 高速フーリエ変換
User tubo28
Language C++11 (GCC 4.9.2)
Score 100
Code Size 3067 Byte
Status AC
Exec Time 709 ms
Memory 35628 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:75:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:79:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
                            ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 33
Set Name Test Cases
Sample 00_sample_01
All 00_sample_01, 01_00_01, 01_01_19, 01_02_31, 01_03_22, 01_04_31, 01_05_40, 01_06_15, 01_07_39, 01_08_28, 01_09_30, 01_10_23, 01_11_33, 01_12_11, 01_13_28, 01_14_41, 01_15_26, 01_16_49, 01_17_34, 01_18_02, 01_19_33, 01_20_29, 02_00_51254, 02_01_82431, 02_02_17056, 02_03_34866, 02_04_6779, 02_05_65534, 02_06_65535, 02_07_65536, 02_08_65537, 02_09_65538, 02_10_100000
Case Name Status Exec Time Memory
00_sample_01 AC 42 ms 8988 KB
01_00_01 AC 41 ms 8992 KB
01_01_19 AC 41 ms 9004 KB
01_02_31 AC 41 ms 9004 KB
01_03_22 AC 43 ms 8988 KB
01_04_31 AC 43 ms 8992 KB
01_05_40 AC 41 ms 9004 KB
01_06_15 AC 41 ms 8988 KB
01_07_39 AC 41 ms 8984 KB
01_08_28 AC 40 ms 8992 KB
01_09_30 AC 40 ms 8984 KB
01_10_23 AC 40 ms 8996 KB
01_11_33 AC 39 ms 8988 KB
01_12_11 AC 39 ms 9000 KB
01_13_28 AC 39 ms 8992 KB
01_14_41 AC 40 ms 8988 KB
01_15_26 AC 38 ms 8996 KB
01_16_49 AC 39 ms 8996 KB
01_17_34 AC 39 ms 8984 KB
01_18_02 AC 39 ms 8992 KB
01_19_33 AC 39 ms 8980 KB
01_20_29 AC 40 ms 8928 KB
02_00_51254 AC 349 ms 22420 KB
02_01_82431 AC 647 ms 34564 KB
02_02_17056 AC 175 ms 15092 KB
02_03_34866 AC 315 ms 21396 KB
02_04_6779 AC 73 ms 10620 KB
02_05_65534 AC 383 ms 23324 KB
02_06_65535 AC 379 ms 23336 KB
02_07_65536 AC 664 ms 33564 KB
02_08_65537 AC 674 ms 33496 KB
02_09_65538 AC 679 ms 33564 KB
02_10_100000 AC 709 ms 35628 KB