提交记录 5433


用户 题目 状态 得分 用时 内存 语言 代码长度
chen_zhe 1002i. 【模板题】多项式乘法 Memory Limit Exceeded 0 0 ns 0 KB C++ 2.23 KB
提交时间 评测时间
2018-08-22 18:32:11 2020-08-01 00:17:10
// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>

using namespace std;

int n,m;

const long double PI=acos(-1.0);

struct Complex
{
    long double x,y;
}a[4200000],b[4200000];

Complex operator + (Complex a,Complex b)
{
    return {a.x+b.x,a.y+b.y};
}

Complex operator - (Complex a,Complex b)
{
    return {a.x-b.x,a.y-b.y};
}

Complex operator * (Complex a,Complex b)
{
    return {a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};
}

int lim=1,l,r[4200000];

void FFT(Complex *A,int type)
{
    for (int i=0;i<lim;i++)
        if (i<r[i])
            swap(A[i],A[r[i]]);
    for (int mid=1;mid<lim;mid<<=1)
    {
        Complex Wn={cos(PI/mid),type*sin(PI/mid)};
        for (int j=0;j<lim;j+=(mid<<1))
        {
            Complex W={1,0};
            for (int k=0;k<mid;k++)
            {
                Complex x=A[j+k],y=W*A[j+mid+k];
                A[j+k]=x+y;
                A[j+mid+k]=x-y;
                W=W*Wn;	
            } 
        }
    }
}

struct io
{
    char ibuf[26777259] , * s , obuf[26777259] , * t;
    int a[24];
    io() : t( obuf )
    {
        s[ fread( s = ibuf , 1 , 26777259 , stdin ) ] = 0;
    }
    ~io()
    {
        fwrite( obuf , 1 , t - obuf , stdout );
    }
    inline int read()
    {
        register int u = 0;
        while( * s < 48 ) s++;
        while( * s > 32 )
            u = u * 10 + * s++ - 48;
        return u;
    }
    template < class T >
    inline void print( register T u )
    {
        static int * q = a;
        if( !u ) * t++ = 48;
        else
        {
            while( u ) * q++ = u % 10 + 48 , u /= 10;
            while( q != a )
                * t++ = * --q;
        }
        * t++ = ' ';
    }
} ip;
   
#define read ip.read
#define print ip.print

int main()
{
    n=read();m=read();
    for (int i=0;i<=n;i++)
        a[i].x=read();
    for (int i=0;i<=m;i++)
        b[i].x=read();
    while (lim<=n+m)
    {
        lim<<=1;
        l++;
    }
    for (int i=0;i<lim;i++)
        r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
    FFT(a,1);
    FFT(b,1);
    for (int i=0;i<=lim;i++)
        a[i]=a[i]*b[i];
    FFT(a,-1);
    for (int i=0;i<=n+m;i++)
        print((int)(a[i].x/lim+0.5));
    return 0;
}
//苟利国家生死以,岂因祸福避趋之

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #10 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #20 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #30 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #40 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #50 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #60 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #70 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #80 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #90 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #100 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #110 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #120 ns0 KBMemory Limit ExceededScore: 0

Subtask #1 Testcase #130 ns0 KBMemory Limit ExceededScore: 0


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