ソースコード 拡げる

Copy
```#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

int pow_2_at_least(int n) {
#if 0
int y = 1;
while (y < n) y <<= 1;
return y;
#endif
if (n <= 0) return 0;
--n;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
return n + 1;
}

typedef complex<double> Cdbl;

void dft(vector<Cdbl>& f, int n, bool inv=false){ // in-place
if (n == 1) return;
int h = n/2;
vector<Cdbl> f0(h), f1(h);
for (int i=0; i<h; ++i) {
f0[i] = f[i*2];
f1[i] = f[i*2+1];
}
dft(f0, h, inv);
dft(f1, h, inv);
double th = M_PI * 2 / n;
if (inv) th = -th;
Cdbl u(cos(th), sin(th)), ui(1, 0);
for (int i=0; i<n; ++i) {
f[i] = f0[i%h] + ui*f1[i%h];
ui *= u;
}
}
inline void idft(vector<Cdbl>& f, int n){
dft(f, n, true);
rep(i,n) f[i] /= n;
}

int main() {
int N; cin >> N;
assert(IN(N,1,100000));

int _n = pow_2_at_least(N*2 + 1);
vector<Cdbl> g(_n, 0), h(_n, 0);

rep(i,N){
int A,B; cin >> A>>B;
g[1+i] = A;
h[1+i] = B;
}

dft(g, _n);
dft(h, _n);
vector<Cdbl> f(_n, 0);
rep(i,_n) f[i] = g[i] * h[i];
idft(f, _n);

rep1(k, N*2){
cout << (ll)round(f[k].real()) << endl;
}
return 0;
}
```

#### 提出情報

提出日時 2018-05-30 07:50:34+0900 C - 高速フーリエ変換 naoya_t C++14 (GCC 5.4.1) 100 2375 Byte AC 866 ms 20764 KB

#### ジャッジ結果

セット名 Sample All

 AC × 1
 AC × 33
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_01 5 ms 640 KB
01_00_01 1 ms 256 KB
01_01_19 1 ms 256 KB
01_02_31 1 ms 256 KB
01_03_22 1 ms 256 KB
01_04_31 1 ms 256 KB
01_05_40 2 ms 256 KB
01_06_15 1 ms 256 KB
01_07_39 2 ms 256 KB
01_08_28 1 ms 256 KB
01_09_30 1 ms 256 KB
01_10_23 1 ms 256 KB
01_11_33 2 ms 256 KB
01_12_11 1 ms 256 KB
01_13_28 1 ms 256 KB
01_14_41 2 ms 256 KB
01_15_26 1 ms 256 KB
01_16_49 2 ms 256 KB
01_17_34 2 ms 256 KB
01_18_02 1 ms 256 KB
01_19_33 2 ms 256 KB
01_20_29 1 ms 256 KB
02_00_51254 423 ms 10532 KB
02_01_82431 798 ms 20764 KB
02_02_17056 183 ms 5420 KB
02_03_34866 371 ms 10532 KB
02_04_6779 53 ms 1532 KB
02_05_65534 481 ms 10532 KB
02_06_65535 476 ms 10532 KB
02_07_65536 740 ms 20764 KB
02_08_65537 748 ms 20764 KB
02_09_65538 740 ms 20764 KB
02_10_100000 866 ms 20764 KB