Submission #421890


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}


typedef complex<double> P;

vector<P> dft(vector<P> f, int n) {
  if (n == 1) return f;
  vector<P> f0, f1;
  REP(i,n) {
    if (i & 1) f1.push_back(f[i]);
    else f0.push_back(f[i]);
  }
  f0 = dft(f0, n/2);
  f1 = dft(f1, n/2);
  P zeta = polar(1.0, 2*PI/n);
  P pow_zeta = 1;
  REP(i,n) {
    f[i] = f0[i%(n/2)] + pow_zeta * f1[i%(n/2)];
    pow_zeta *= zeta;
  }
  return f;
}

vector<P> inverse_dft_sub(vector<P> f, int n) {
  if (n == 1) return f;
  vector<P> f0, f1;
  REP(i,n) {
    if (i & 1) f1.push_back(f[i]);
    else f0.push_back(f[i]);
  }
  f0 = inverse_dft_sub(f0, n/2);
  f1 = inverse_dft_sub(f1, n/2);
  P zeta = polar(1.0,-2*PI/n);
  P pow_zeta = 1;
  REP(i,n) {
    f[i] = f0[i%(n/2)] + pow_zeta * f1[i%(n/2)];
    pow_zeta *= zeta;
  }
  return f;
}

vector<P> inverse_dft(vector<P> f, int n) {
  f = inverse_dft_sub(f, n);
  REP(i,f.size()) f[i] = f[i] * P(1.0/n,0);
  return f;
}

vector<P> multiply(const vector<int> &g, const vector<int> &h) {
  size_t n = 1;
  while(n<g.size()+h.size()+1) n <<= 1;
  vector<P> cg(n), ch(n);
  REP(i,g.size()) cg[i] = g[i];
  REP(i,h.size()) ch[i] = h[i];
  auto gg = dft(cg, n);
  auto hh = dft(ch, n);
  vector<P> ff(n);
  REP(i,n) ff[i] = gg[i] * hh[i];
  return inverse_dft(ff, n);
}

int main() {
  int n;
  while(cin >> n) {
    vector<int> A({0});
    vector<int> B({0});
    REP(i,n) {
      int a,b;
      input(a,b);
      A.push_back(a);
      B.push_back(b);
    }
    auto f = multiply(A,B);
    for (int i=1; i<=2*n; ++i)
      output(int(round(f[i].real())));
  }
}

Submission Info

Submission Time
Task C - 高速フーリエ変換
User sune2
Language C++11 (GCC 4.9.2)
Score 100
Code Size 3823 Byte
Status AC
Exec Time 1141 ms
Memory 42544 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 28 ms 804 KB
01_00_01 AC 25 ms 920 KB
01_01_19 AC 28 ms 908 KB
01_02_31 AC 26 ms 800 KB
01_03_22 AC 25 ms 796 KB
01_04_31 AC 26 ms 796 KB
01_05_40 AC 27 ms 796 KB
01_06_15 AC 26 ms 792 KB
01_07_39 AC 27 ms 740 KB
01_08_28 AC 26 ms 800 KB
01_09_30 AC 25 ms 800 KB
01_10_23 AC 27 ms 728 KB
01_11_33 AC 26 ms 920 KB
01_12_11 AC 27 ms 796 KB
01_13_28 AC 26 ms 732 KB
01_14_41 AC 28 ms 796 KB
01_15_26 AC 26 ms 796 KB
01_16_49 AC 26 ms 912 KB
01_17_34 AC 26 ms 788 KB
01_18_02 AC 26 ms 788 KB
01_19_33 AC 26 ms 920 KB
01_20_29 AC 25 ms 792 KB
02_00_51254 AC 564 ms 21720 KB
02_01_82431 AC 1099 ms 42408 KB
02_02_17056 AC 283 ms 11252 KB
02_03_34866 AC 548 ms 21588 KB
02_04_6779 AC 90 ms 3404 KB
02_05_65534 AC 588 ms 21792 KB
02_06_65535 AC 1095 ms 42316 KB
02_07_65536 AC 1084 ms 42280 KB
02_08_65537 AC 1084 ms 42268 KB
02_09_65538 AC 1080 ms 42268 KB
02_10_100000 AC 1141 ms 42544 KB