Submission #421423


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<<20];
    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 ? len-k*i-1 : 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);
        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 3016 Byte
Status AC
Exec Time 718 ms
Memory 43896 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:74:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:78: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 73 ms 17192 KB
01_00_01 AC 62 ms 17236 KB
01_01_19 AC 58 ms 17252 KB
01_02_31 AC 74 ms 17252 KB
01_03_22 AC 60 ms 17264 KB
01_04_31 AC 60 ms 17260 KB
01_05_40 AC 57 ms 17268 KB
01_06_15 AC 58 ms 17256 KB
01_07_39 AC 60 ms 17260 KB
01_08_28 AC 61 ms 17260 KB
01_09_30 AC 60 ms 17260 KB
01_10_23 AC 60 ms 17268 KB
01_11_33 AC 57 ms 17256 KB
01_12_11 AC 57 ms 17252 KB
01_13_28 AC 58 ms 17260 KB
01_14_41 AC 57 ms 17256 KB
01_15_26 AC 57 ms 17256 KB
01_16_49 AC 61 ms 17256 KB
01_17_34 AC 58 ms 17260 KB
01_18_02 AC 57 ms 17260 KB
01_19_33 AC 57 ms 17260 KB
01_20_29 AC 56 ms 17244 KB
02_00_51254 AC 371 ms 30692 KB
02_01_82431 AC 697 ms 42820 KB
02_02_17056 AC 196 ms 23360 KB
02_03_34866 AC 338 ms 29664 KB
02_04_6779 AC 94 ms 18860 KB
02_05_65534 AC 417 ms 31600 KB
02_06_65535 AC 403 ms 31592 KB
02_07_65536 AC 691 ms 41816 KB
02_08_65537 AC 688 ms 41824 KB
02_09_65538 AC 681 ms 41812 KB
02_10_100000 AC 718 ms 43896 KB