Submission #1139122
Source Code Expand
#include <stdio.h>
#include <complex.h>
#define PI2 6.28318530717958647692
const int k = 18;
const int m = (1 << 18);
typedef double complex cmplx;
cmplx C[1<<18];
cmplx w[1<<17];
const int mod10[200] = {
0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
,0,1,2,3,4,5,6,7,8,9 ,0,1,2,3,4,5,6,7,8,9
};
const int div10[200] = {
0,0,0,0,0,0,0,0,0,0 ,1,1,1,1,1,1,1,1,1,1
,2,2,2,2,2,2,2,2,2,2 ,3,3,3,3,3,3,3,3,3,3
,4,4,4,4,4,4,4,4,4,4 ,5,5,5,5,5,5,5,5,5,5
,6,6,6,6,6,6,6,6,6,6 ,7,7,7,7,7,7,7,7,7,7
,8,8,8,8,8,8,8,8,8,8 ,9,9,9,9,9,9,9,9,9,9
,10,10,10,10,10,10,10,10,10,10 ,11,11,11,11,11,11,11,11,11,11
,12,12,12,12,12,12,12,12,12,12 ,13,13,13,13,13,13,13,13,13,13
,14,14,14,14,14,14,14,14,14,14 ,15,15,15,15,15,15,15,15,15,15
,16,16,16,16,16,16,16,16,16,16 ,17,17,17,17,17,17,17,17,17,17
,18,18,18,18,18,18,18,18,18,18 ,19,19,19,19,19,19,19,19,19,19
};
void read_int(int *x){
char c=0;
while(c<'0'||c>'9') c = getchar_unlocked();
*x = c-'0';
c = getchar_unlocked();
while(c>='0'&&c<='9') {
*x *= 10;
*x += c-'0';
c = getchar_unlocked();
}
}
void write_int(int x){
int i;
static char buf[13]=" \n";
if(x==0){
fputs_unlocked("0\n", stdout);
return;
}
for(i=10; x; i--){
if(x >= 200){
buf[i] = '0' + x % 10;
x /= 10;
}
else {
buf[i] = '0' + mod10[x];
x = div10[x];
}
}
fputs_unlocked(buf+1+i, stdout);
}
unsigned minus(unsigned x) {
int y = 1 << (31-__builtin_clz(x));
return (~x&(y-1))^y;
}
void fft(cmplx *A, int k){
int m = 1 << k;
int u = 1;
int v = m/2;
for(int i=k;i>0;i--){
for(int jh=0;jh<u;jh++){
cmplx wj = w[jh];
for(int j = jh << i, je = j|v;j<je; j++){
cmplx Ajv = wj * A[j|v];
A[j|v] = A[j] - Ajv;
A[j] += Ajv;
}
}
u <<= 1;
v >>= 1;
}
}
void ifft(cmplx *A, int k){
int m = 1 << k;
int u = m/2;
int v = 1;
for(int i=1;i<=k;i++){
for(int jh=0;jh<u;jh++){
cmplx wj = conj(w[jh]);
for(int j = jh << i, je = j|v;j<je; j++){
cmplx 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, cmplx 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;
const double arg = -PI2/m;
for(int i=1, j=m/4; j; i<<=1, j>>=1){
w[i] = cexp(I * (arg * j));
}
genw(0, m/4, 1);
read_int(&n);
for(int i=1;i<=n;i++){
int a, b;
read_int(&a);
read_int(&b);
C[i] = a + b*I;
}
// k = 33 - __builtin_clz(n);
// m = 1 << k;
fft(C, k);
C[0] = 4 * creal(C[0]) * cimag(C[0]) * I;
C[1] = 4 * creal(C[1]) * cimag(C[1]) * I;
for(int i = 2; i < m; i+=2){
int j = minus(i);
C[i] = (C[i] + conj(C[j]))*(C[i] - conj(C[j]));
C[j] = -conj(C[i]);
}
for(int i = 0; i < m; i+=2){
C[i/2] = C[i]+C[i^1] + (C[i]-C[i^1])*w[i/2]*I;
}
ifft(C, k-1);
for(int i=1;i<=n;i++){
write_int(-creal(C[i])/(4*m)+0.5);
write_int(cimag(C[i])/(4*m)+0.5);
}
}
Submission Info
Submission Time
2017-03-03 12:02:40+0900
Task
C - 高速フーリエ変換
User
ryuhei
Language
C (Clang 3.8.0)
Score
100
Code Size
3554 Byte
Status
AC
Exec Time
27 ms
Memory
8192 KB
Compile Error
./Main.c:59:5: warning: implicit declaration of function 'fputs_unlocked' is invalid in C99 [-Wimplicit-function-declaration]
fputs_unlocked("0\n", stdout);
^
1 warning generated.
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
20 ms
6656 KB
01_00_01
AC
17 ms
6272 KB
01_01_19
AC
17 ms
6272 KB
01_02_31
AC
17 ms
6272 KB
01_03_22
AC
17 ms
6272 KB
01_04_31
AC
17 ms
6272 KB
01_05_40
AC
17 ms
6272 KB
01_06_15
AC
17 ms
6272 KB
01_07_39
AC
17 ms
6272 KB
01_08_28
AC
17 ms
6272 KB
01_09_30
AC
17 ms
6272 KB
01_10_23
AC
17 ms
6272 KB
01_11_33
AC
17 ms
6272 KB
01_12_11
AC
17 ms
6272 KB
01_13_28
AC
17 ms
6272 KB
01_14_41
AC
17 ms
6400 KB
01_15_26
AC
17 ms
6272 KB
01_16_49
AC
17 ms
6272 KB
01_17_34
AC
17 ms
6272 KB
01_18_02
AC
17 ms
6272 KB
01_19_33
AC
17 ms
6272 KB
01_20_29
AC
17 ms
6272 KB
02_00_51254
AC
22 ms
7168 KB
02_01_82431
AC
25 ms
7808 KB
02_02_17056
AC
19 ms
6656 KB
02_03_34866
AC
20 ms
6912 KB
02_04_6779
AC
17 ms
6400 KB
02_05_65534
AC
23 ms
7552 KB
02_06_65535
AC
23 ms
7552 KB
02_07_65536
AC
23 ms
7552 KB
02_08_65537
AC
23 ms
7552 KB
02_09_65538
AC
23 ms
7552 KB
02_10_100000
AC
27 ms
8192 KB