Submission #526151


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
const int N=1<<19;
const double th=2*pi/N;
typedef complex<double> P;
 
void FFT(P a[],double t) {
  for(int m=N; m>=2; m>>=1) {
    int mh=m>>1;
    for(int i=0; i<mh; i++) {
      P w=exp(t*i*P(0,1));
      for(int j=i; j<N; j+=m) {
        int k=j+mh;
        P x=a[j]-a[k];
        a[j]+=a[k];
        a[k]=w*x;
      }
    }
    t*=2;
  }
  int i=0;
  for(int j=1; j<N-1; j++) {
    for(int k=N>>1; k>(i^=k); k>>=1);
    if(j<i) swap(a[i],a[j]);
  }
}

P a[N],b[N];
int d[N],c[N];
void solve() {
  for(int i=0; i<N; i++) {
    a[i]=P(d[i],0);
    b[i]=P(c[i],0);
  }
  FFT(a,th);
  FFT(b,th);
  for(int i=0; i<N; i++) a[i]*=b[i];
  FFT(a,-th);
  for(int i=0; i<N; i++) d[i]=round(a[i].real()/N);
}

void Main() {
  int n;
  R n;
  rep(i,n) cin >> d[i+1] >> c[i+1];
  solve();
  REP(i,1,n*2+1) pr(d[i]);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}

Submission Info

Submission Time
Task C - 高速フーリエ変換
User kzyKT
Language C++ (GCC 4.9.2)
Score 100
Code Size 1991 Byte
Status AC
Exec Time 722 ms
Memory 19888 KB

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 625 ms 19440 KB
01_00_01 AC 570 ms 19364 KB
01_01_19 AC 577 ms 19424 KB
01_02_31 AC 574 ms 19368 KB
01_03_22 AC 575 ms 19372 KB
01_04_31 AC 573 ms 19360 KB
01_05_40 AC 575 ms 19364 KB
01_06_15 AC 583 ms 19376 KB
01_07_39 AC 575 ms 19408 KB
01_08_28 AC 580 ms 19408 KB
01_09_30 AC 586 ms 19416 KB
01_10_23 AC 577 ms 19372 KB
01_11_33 AC 575 ms 19364 KB
01_12_11 AC 579 ms 19372 KB
01_13_28 AC 581 ms 19424 KB
01_14_41 AC 575 ms 19368 KB
01_15_26 AC 577 ms 19368 KB
01_16_49 AC 575 ms 19504 KB
01_17_34 AC 575 ms 19408 KB
01_18_02 AC 575 ms 19364 KB
01_19_33 AC 581 ms 19372 KB
01_20_29 AC 573 ms 19364 KB
02_00_51254 AC 655 ms 19688 KB
02_01_82431 AC 697 ms 19884 KB
02_02_17056 AC 591 ms 19620 KB
02_03_34866 AC 627 ms 19624 KB
02_04_6779 AC 576 ms 19500 KB
02_05_65534 AC 671 ms 19628 KB
02_06_65535 AC 676 ms 19624 KB
02_07_65536 AC 678 ms 19628 KB
02_08_65537 AC 683 ms 19628 KB
02_09_65538 AC 672 ms 19632 KB
02_10_100000 AC 722 ms 19888 KB