记录编号 358246 评测结果 AAAAAAAAAA
题目名称 异化多肽 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 4.810 s
提交时间 2016-12-15 10:53:17 内存使用 68.98 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <list>
#include <cmath>
#include <queue>
#include <vector>
#include <deque>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;
const int MAXN = 3e6+8;
//const int MAXM = (int)(log(MAXN))+3;  //够用即可
const int MAXM = 23;
const int MOD = 1005060097;    
const int G = 5;    
LL quick_pow(LL a, LL b)
{
    LL res = 1;
    LL base = a%MOD;
    while(b)
    {
        if(b & 1)
        {
            res *= base;
            res %= MOD;
        }
        b >>= 1;
        base *= base;
        base %= MOD;
    }
    return res;
}
LL omg[MAXM+1];
void calcOmg()
{
    for(int i = 0; i <= MAXM; i++)
    {
        int k = 1 << i;
        omg[i] = quick_pow(G, (MOD-1)/k);
    }
}
class NTTer
{
public:
    LL a[MAXN];
    LL len;
    void trans()
    {
        int j = len >> 1;
        for(int i = 1; i < len-1; i++)
        {
            if(i < j)swap(a[i], a[j]);
            int k = len >> 1;
            while(j >= k)
            {
                j -= k;
                k >>= 1;
            }
            if(j < k)j += k;
        }
    }
    void NTT(bool DNTT = false)
    {
        trans();
        int id = 0;
        for(int h = 2; h <= len; h <<= 1)
        {
            id++;
            for(int j = 0; j < len; j += h)
            {
                LL omgn = 1;
                for(int k = j; k < j + h/2; k++)
                {
                    LL u = a[k] % MOD;
                    LL t = omgn * a[k + h/2] % MOD;
                    a[k] = (u+t)%MOD;
                    a[k+h/2] = (u-t+MOD)%MOD;
                    omgn = omgn*omg[id]%MOD;
                }
            }
        }
        if(DNTT)
        {
            for(int i = 1; i < len/2; i++)
                swap(a[i], a[len-i]);
            LL inv = quick_pow(len, MOD-2);
            for(int i = 0; i < len; i++)
                a[i] = a[i] * inv % MOD;
        }
    }
    void mul(NTTer &o)
    {
        int s = 1;
        while(s < len+o.len) s<<=1;
        len = o.len = s;
        NTT(false);
        o.NTT(false);
        for(int i = 0; i < len; i++)
            a[i] = a[i]*o.a[i]%MOD;
        NTT(true);
    }   
};
NTTer tmp;
void inv(NTTer &a, NTTer &b, int len)
{
    if(len == 1)
    {
        b.a[0] = pow(a.a[0], MOD-2);
        return;
    }
    inv(a, b, len>>1);
    int mh = len<<1;
    memcpy(tmp.a, a.a, sizeof(LL)*len);
    b.len = mh;
    tmp.len = mh;
    b.NTT();
    tmp.NTT();
    for(int i = 0; i < mh; i++)
        tmp.a[i] = b.a[i]*((2-tmp.a[i]*b.a[i]%MOD+MOD)%MOD)%MOD;
    tmp.NTT(true);
    memcpy(b.a, tmp.a, sizeof(LL)*len);
    memset(b.a+len, 0, sizeof(LL)*len);
}
NTTer x, y;
int main()
{
    freopen("polypeptide.in", "r", stdin);
    freopen("polypeptide.out", "w", stdout);
    calcOmg();
    int n, m;
    scanf("%d %d", &n, &m);
    int len = 1;
    while(len <= n)len<<=1;
    for(int i = 1, v; i <= m; i++)
        scanf("%d", &v), --x.a[v];
    x.a[0]++;
    inv(x, y, len);
    printf("%lld\n", (y.a[n]%MOD+MOD)%MOD);
    return 0;
}