Submission #2739303

Source Code Expand

Copy
```#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;

using Complex = complex<double>;
vector<Complex> dft(vector<Complex> A, int N, int sgn = 1) {
if(N == 1) return A;

vector<Complex> F(N / 2), G(N / 2);
for(int i=0; i<N/2; i++) {
F[i] = A[2 * i + 0];
G[i] = A[2 * i + 1];
}

F = dft(F, N / 2, sgn);
G = dft(G, N / 2, sgn);

Complex zeta(cos(2.0 * M_PI / N), sin(2.0 * M_PI / N) * sgn);
Complex pow_zeta = 1;

for(int i=0; i<N; i++) {
A[i] = F[i % (N / 2)] + pow_zeta * G[i % (N / 2)];
pow_zeta *= zeta;
}
return A;
}

vector<Complex> inv_dft(vector<Complex> A, int N) {
A = dft(A, N, -1);
for(int i=0; i<N; i++) {
A[i] /= N;
}
return A;
}

vector<Complex> multiply(vector<Complex> A, vector<Complex> B) {
int sz = A.size() + B.size() + 1;
int N = 1; while(N < sz) N *= 2;

A.resize(N), B.resize(N);
A = dft(A, N);
B = dft(B, N);

vector<Complex> F(N);
for(int i=0; i<N; i++) {
F[i] = A[i] * B[i];
}
return inv_dft(F, N);
}

int main() {
int N; scanf("%d", &N);

vector<Complex> A(N+1), B(N+1);
A[0] = B[0] = Complex(0);
for(int i=1; i<=N; i++) {
int vl, vr; scanf("%d%d", &vl, &vr);
A[i] = Complex(vl);
B[i] = Complex(vr);
}

vector<Complex> ans = multiply(A, B);
for(int i=1; i<=2*N; i++) {
printf("%d\n", (int)(ans[i].real() + 0.5));
}
return 0;
}```

#### Submission Info

Submission Time 2018-06-24 19:58:41+0900 C - 高速フーリエ変換 Tsuta_J C++14 (GCC 5.4.1) 100 1576 Byte AC 643 ms 37108 KB

#### Compile Error

```./Main.cpp: In function ‘int main()’:
./Main.cpp:54:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int N; scanf("%d", &N);
^
./Main.cpp:59:44: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int vl, vr; scanf("%d%d", &vl, &vr);
^
```

#### Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_sample_01
All 100 / 100 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 4 ms 512 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 3 ms 256 KB
01_06_15 1 ms 256 KB
01_07_39 1 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 1 ms 256 KB
01_12_11 1 ms 256 KB
01_13_28 1 ms 256 KB
01_14_41 1 ms 256 KB
01_15_26 1 ms 256 KB
01_16_49 1 ms 256 KB
01_17_34 1 ms 256 KB
01_18_02 1 ms 256 KB
01_19_33 1 ms 256 KB
01_20_29 1 ms 256 KB
02_00_51254 314 ms 18212 KB
02_01_82431 637 ms 35540 KB
02_02_17056 152 ms 8916 KB
02_03_34866 312 ms 17700 KB
02_04_6779 38 ms 2460 KB
02_05_65534 320 ms 18680 KB
02_06_65535 636 ms 35044 KB
02_07_65536 632 ms 35044 KB
02_08_65537 637 ms 37108 KB
02_09_65538 638 ms 35044 KB
02_10_100000 643 ms 36148 KB