Submission #1134526
Source Code Expand
#include <cstdio>
#include <complex>
#include <cmath>
int m;
int k;
typedef std::complex<double> complex;
complex C[1<<18];
complex w[1<<17];
unsigned clp2(unsigned x) {
x = x - 1;
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >>16);
return x + 1;
}
unsigned increv(unsigned x) {
unsigned mm=m/2;
x = x ^ mm;
while (x < mm) {
mm >>= 1;
x = x ^ mm;
}
return x;
}
void fft(complex *A){
int u = 1;
int v = m/2;
for(int i=k;i>0;i--){
for(int jh=0;jh<u;jh++){
complex wj = w[jh];
for(int j = jh << i, je = j|v;j<je; j++){
complex Ajv = wj * A[j|v];
A[j|v] = A[j] - Ajv;
A[j] += Ajv;
}
}
u <<= 1;
v >>= 1;
}
}
void ifft(complex *A){
int u = m/2;
int v = 1;
for(int i=1;i<=k;i++){
for(int jh=0;jh<u;jh++){
complex wj = std::conj(w[jh]);
for(int j = jh << i, je = j|v;j<je; j++){
complex Ajv = A[j] - A[j|v];
A[j] += A[j|v];
A[j|v] = wj * Ajv;
}
}
u >>= 1;
v <<= 1;
}
}
void genw(int i, int b, complex z){
if(b == 0)
w[i] = z;
else {
genw(i, b>>1, z);
genw(i|b, b>>1, z*w[b]);
}
}
int main(){
int n;
std::scanf("%d", &n);
for(int i=1;i<=n;i++){
int a, b;
std::scanf(" %d %d", &a, &b);
C[i].real(a);
C[i].imag(b);
}
m = clp2(n+1) << 1;
k = __builtin_ctz(m);
double arg = -2*M_PI/m;
for(int i=1, j=m/4; j; i<<=1, j>>=1){
double argj = arg * j;
w[i].real(std::cos(argj));
w[i].imag(std::sin(argj));
}
genw(0, m/4, 1);
fft(C);
C[0] = C[0].real() * C[0].imag();
for(int i=m/2, j=m-1;i!=(m/2|1);j=(~i&(m-1)),i=increv(i)){
C[i] = (C[i] + std::conj(C[j]))*(C[i] - std::conj(C[j]));
C[j].real(C[i].imag()/4.0);
C[j].imag(C[i].real()/4.0);
C[i].real(C[j].real());
C[i].imag(-C[j].imag());
}
ifft(C);
for(int i=1;i<=2*n;i++){
std::printf("%d\n", (int) ((C[i].real()+0.5)/m));
}
}
Submission Info
Submission Time |
|
Task |
C - 高速フーリエ変換 |
User |
ryuhei |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2099 Byte |
Status |
AC |
Exec Time |
73 ms |
Memory |
8192 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:78:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
std::scanf("%d", &n);
^
./Main.cpp:81:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
std::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 |
1 ms |
2176 KB |
01_00_01 |
AC |
1 ms |
2176 KB |
01_01_19 |
AC |
1 ms |
2176 KB |
01_02_31 |
AC |
1 ms |
2176 KB |
01_03_22 |
AC |
1 ms |
2176 KB |
01_04_31 |
AC |
1 ms |
2176 KB |
01_05_40 |
AC |
1 ms |
2176 KB |
01_06_15 |
AC |
1 ms |
2176 KB |
01_07_39 |
AC |
1 ms |
2176 KB |
01_08_28 |
AC |
1 ms |
2176 KB |
01_09_30 |
AC |
1 ms |
2176 KB |
01_10_23 |
AC |
1 ms |
2176 KB |
01_11_33 |
AC |
1 ms |
2176 KB |
01_12_11 |
AC |
1 ms |
2176 KB |
01_13_28 |
AC |
1 ms |
2176 KB |
01_14_41 |
AC |
1 ms |
2176 KB |
01_15_26 |
AC |
1 ms |
2176 KB |
01_16_49 |
AC |
1 ms |
2176 KB |
01_17_34 |
AC |
1 ms |
2176 KB |
01_18_02 |
AC |
1 ms |
2176 KB |
01_19_33 |
AC |
1 ms |
2176 KB |
01_20_29 |
AC |
1 ms |
2176 KB |
02_00_51254 |
AC |
35 ms |
6272 KB |
02_01_82431 |
AC |
65 ms |
7808 KB |
02_02_17056 |
AC |
15 ms |
3072 KB |
02_03_34866 |
AC |
30 ms |
5888 KB |
02_04_6779 |
AC |
5 ms |
2432 KB |
02_05_65534 |
AC |
40 ms |
6528 KB |
02_06_65535 |
AC |
40 ms |
6528 KB |
02_07_65536 |
AC |
60 ms |
7552 KB |
02_08_65537 |
AC |
60 ms |
7552 KB |
02_09_65538 |
AC |
60 ms |
7552 KB |
02_10_100000 |
AC |
73 ms |
8192 KB |