Submission #421323


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

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

vector<Complex> mul(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);
    vector<Complex> z(n+1);
    rep(i,n+1) z[i] = polar<Real>(1,2*PI/n*i);
    vector<Complex> gg = fft(g,z), hh = fft(h,z);
    vector<Complex> ff(n);
    rep(i,n) ff[i] = gg[i]*hh[i];
    vector<Complex> res = fft(ff,z,1);
    rep(i,n) res[i] /= n;
    return res;
}

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 = mul(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 2826 Byte
Status AC
Exec Time 887 ms
Memory 45492 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:68:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:72: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 28 ms 920 KB
01_00_01 AC 26 ms 796 KB
01_01_19 AC 26 ms 804 KB
01_02_31 AC 26 ms 792 KB
01_03_22 AC 25 ms 920 KB
01_04_31 AC 25 ms 920 KB
01_05_40 AC 26 ms 924 KB
01_06_15 AC 26 ms 928 KB
01_07_39 AC 25 ms 924 KB
01_08_28 AC 36 ms 744 KB
01_09_30 AC 26 ms 804 KB
01_10_23 AC 25 ms 920 KB
01_11_33 AC 25 ms 788 KB
01_12_11 AC 25 ms 928 KB
01_13_28 AC 26 ms 800 KB
01_14_41 AC 26 ms 796 KB
01_15_26 AC 26 ms 804 KB
01_16_49 AC 26 ms 920 KB
01_17_34 AC 26 ms 796 KB
01_18_02 AC 27 ms 804 KB
01_19_33 AC 27 ms 812 KB
01_20_29 AC 31 ms 796 KB
02_00_51254 AC 425 ms 21148 KB
02_01_82431 AC 878 ms 44284 KB
02_02_17056 AC 207 ms 11376 KB
02_03_34866 AC 394 ms 20124 KB
02_04_6779 AC 67 ms 3456 KB
02_05_65534 AC 448 ms 22052 KB
02_06_65535 AC 447 ms 22060 KB
02_07_65536 AC 827 ms 43284 KB
02_08_65537 AC 842 ms 43300 KB
02_09_65538 AC 846 ms 43292 KB
02_10_100000 AC 887 ms 45492 KB