提交记录 7837


用户 题目 状态 得分 用时 内存 语言 代码长度
rvalue 1002i. 【模板题】多项式乘法 Accepted 100 66.418 ms 15264 KB C++ 2.03 KB
提交时间 评测时间
2019-01-25 19:01:00 2020-08-01 01:09:01
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

const int MAXN=270000;
const int DFT=1;
const int IDFT=-1;
const double PI=acos(-1);

struct Complex{
    double real;
    double imag;
    Complex(double r=0,double i=0){
        this->real=r;
        this->imag=i;
    }
};
Complex operator+(const Complex& a,const Complex& b){
    return Complex(a.real+b.real,a.imag+b.imag);
}
Complex operator-(const Complex& a,const Complex& b){
    return Complex(a.real-b.real,a.imag-b.imag);
}
Complex operator*(const Complex& a,const Complex& b){
    return Complex(a.real*b.real-a.imag*b.imag,a.real*b.imag+a.imag*b.real);
}

Complex a[MAXN],b[MAXN],c[MAXN];

int n;             //Length of a
int m;             //Length of b
int bln=1;         //Binary Length
int bct;           //Bit Count
int len;           //Length Sum
int rev[MAXN];     //Binary Reverse Sort

void Initialize();
void FFT(Complex*,int,int);

int main(){
    Initialize();
    FFT(a,bln,DFT);
    FFT(b,bln,DFT);
    for(int i=0;i<=bln;i++){
        c[i]=a[i]*b[i];
    }
    FFT(c,bln,IDFT);
    for(int i=0;i<=len;i++){
        printf("%d ",int(c[i].real/bln+0.5));
    }
    putchar('\n');
    return 0;
}

void FFT(Complex* a,int len,int opt){
    for(int i=0;i<len;i++)
        if(i<rev[i])
            std::swap(a[i],a[rev[i]]);
    for(int i=1;i<len;i<<=1){
        Complex wn=Complex(cos(PI/i),opt*sin(PI/i));
        int step=i<<1;
        for(int j=0;j<len;j+=step){
            Complex w=Complex(1,0);
            for(int k=0;k<i;k++,w=w*wn){
                Complex x=a[j+k];
                Complex y=w*a[j+k+i];
                a[j+k]=x+y;
                a[j+k+i]=x-y;
            }
        }
    }
}

void Initialize(){
    scanf("%d%d",&n,&m);
    len=n+m;
    while(bln<=len){
        bct++;
        bln<<=1;
    }
    for(int i=0;i<bln;i++){
        rev[i]=(rev[i>>1]>>1)|((i&1)<<(bct-1));
    }
    for(int i=0;i<=n;i++){
        scanf("%lf",&a[i].real);
    }
    for(int i=0;i<=m;i++){
        scanf("%lf",&b[i].real);
    }
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #11.402 ms12 MB + 420 KBAcceptedScore: 0

Subtask #1 Testcase #266.165 ms14 MB + 848 KBAcceptedScore: 0

Subtask #1 Testcase #330.93 ms13 MB + 188 KBAcceptedScore: 100

Subtask #1 Testcase #431.043 ms13 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #51.409 ms12 MB + 420 KBAcceptedScore: 0

Subtask #1 Testcase #61.405 ms12 MB + 420 KBAcceptedScore: 0

Subtask #1 Testcase #71.402 ms12 MB + 420 KBAcceptedScore: 0

Subtask #1 Testcase #859.943 ms14 MB + 580 KBAcceptedScore: 0

Subtask #1 Testcase #959.981 ms14 MB + 580 KBAcceptedScore: 0

Subtask #1 Testcase #1053.791 ms14 MB + 312 KBAcceptedScore: 0

Subtask #1 Testcase #1166.418 ms14 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #1266.339 ms13 MB + 808 KBAcceptedScore: 0

Subtask #1 Testcase #131.452 ms12 MB + 420 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-26 10:51:51 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用