Submission #421403
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 FFT {
Complex z[1<<20];
int len;
vector<Complex> fastFourierTransform(vector<Complex> & f, 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 = fastFourierTransform(f0,inv), f1 = 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 f;
}
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);
vector<Complex> g_ = fastFourierTransform(g);
vector<Complex> h_ = fastFourierTransform(h);
vector<Complex> f_(n);
rep(i,n) f_[i] = g_[i]*h_[i];
vector<Complex> res = fastFourierTransform(f_,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 = FFT::convolution(g,h);
for(int i=1;i<=n*2;i++) printf("%d\n",(int)(f[i].real()+0.5));
}
Submission Info
Submission Time
2015-06-06 23:44:11+0900
Task
C - 高速フーリエ変換
User
tubo28
Language
C++11 (GCC 4.9.2)
Score
100
Code Size
3071 Byte
Status
AC
Exec Time
918 ms
Memory
57728 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:73:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:77: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
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
71 ms
17228 KB
01_00_01
AC
61 ms
17256 KB
01_01_19
AC
60 ms
17264 KB
01_02_31
AC
59 ms
17272 KB
01_03_22
AC
56 ms
17264 KB
01_04_31
AC
62 ms
17260 KB
01_05_40
AC
64 ms
17260 KB
01_06_15
AC
61 ms
17260 KB
01_07_39
AC
59 ms
17268 KB
01_08_28
AC
57 ms
17256 KB
01_09_30
AC
57 ms
17252 KB
01_10_23
AC
57 ms
17260 KB
01_11_33
AC
57 ms
17252 KB
01_12_11
AC
57 ms
17252 KB
01_13_28
AC
57 ms
17260 KB
01_14_41
AC
56 ms
17260 KB
01_15_26
AC
57 ms
17392 KB
01_16_49
AC
56 ms
17268 KB
01_17_34
AC
57 ms
17260 KB
01_18_02
AC
57 ms
17256 KB
01_19_33
AC
57 ms
17244 KB
01_20_29
AC
57 ms
17252 KB
02_00_51254
AC
441 ms
35548 KB
02_01_82431
AC
875 ms
56648 KB
02_02_17056
AC
239 ms
26684 KB
02_03_34866
AC
420 ms
34528 KB
02_04_6779
AC
96 ms
19648 KB
02_05_65534
AC
464 ms
36460 KB
02_06_65535
AC
464 ms
36460 KB
02_07_65536
AC
864 ms
55644 KB
02_08_65537
AC
851 ms
55656 KB
02_09_65538
AC
859 ms
55648 KB
02_10_100000
AC
918 ms
57728 KB