Codeforces 286E

  1 #include <cstdio>
  2 #include <cmath>
  3 #include <cstring>
  4 #include <algorithm>
  5 #include <cstdlib>
  6 #include <ctime>
  7 #include <set>
  8 #include <map>
  9 using namespace std;
 10 
 11 const int maxn=int(1e6)+100;
 12 const double eps=0.5;
 13 const double PI=acos(-1);
 14 
 15 struct Complex
 16 {
 17     double real, imag;
 18 
 19     Complex(double _x=0, double _y=0):real(_x), imag(_y) {}
 20 
 21     Complex operator + (Complex b)
 22     {
 23         return Complex(real+b.real, imag+b.imag);
 24     }
 25 
 26     Complex operator - (Complex b)
 27     {
 28         return Complex(real-b.real, imag-b.imag);
 29     }
 30 
 31     Complex operator * (Complex b)
 32     {
 33         return Complex(real*b.real-imag*b.imag, real*b.imag+b.real*imag);
 34     }
 35 };
 36 
 37 int n, m;
 38 int lg, wide;
 39 bool vis[maxn];
 40 int ans[maxn], rev[maxn*8];
 41 Complex a[maxn*8];
 42 
 43 void init()
 44 {
 45     scanf("%d%d", &n, &m);
 46     for (int i=1; i<=n; ++i)
 47     {
 48         int num;
 49         scanf("%d", &num);
 50         vis[num]=true;
 51         a[num].real=1;
 52     }
 53 }
 54 void init_order()
 55 {
 56     for (int i=0; i<wide; ++i)
 57         for (int j=0; j<lg; ++j)
 58             rev[i]=(rev[i]<<1) | (i>>j & 1);
 59 }
 60 void FFT(int type)
 61 {
 62     for (int i=0; i<wide; ++i)
 63         if (rev[i]>i) swap(a[i], a[rev[i]]);
 64 
 65     for (int i=2; i<=wide; i<<=1)
 66         for (int j=0; j<wide; j+=i)
 67         {
 68             Complex w(cos(PI*2/i), sin(PI*2/i*(-type)));
 69             Complex wn(1, 0);
 70             for (int k=0; k<i>>1; ++k, wn=wn*w)
 71             {
 72                 Complex tmp=a[j+k];
 73                 a[j+k]=tmp+wn*a[j+k+(i>>1)];
 74                 a[j+k+(i>>1)]=tmp-wn*a[j+k+(i>>1)];
 75             }
 76         }
 77 }
 78 void solve()
 79 {
 80     lg=0;
 81     while (1<<lg<m*2) ++lg;
 82     wide=1<<lg;
 83     init_order();   
 84     FFT(1);
 85     for (int i=0; i<wide; ++i) a[i]=a[i]*a[i];
 86     FFT(-1);
 87     for (int i=0; i<wide; ++i) a[i].real/=wide;
 88 /*
 89     for (int i=0; i<wide; ++i)
 90         printf("%d ", int(a[i].real+0.5));
 91 */      
 92     bool flag=true;
 93     for (int i=0; i<=m; ++i)
 94         if (a[i].real>eps && !vis[i])
 95         {
 96             flag=false;
 97             break;
 98         }
 99     if (!flag) printf("NO\n");
100     else
101     {
102         printf("YES\n");
103         for (int i=0; i<=m; ++i)
104             if (vis[i] && a[i].real<eps)
105                 ans[++ans[0]]=i;
106         printf("%d\n", ans[0]);
107         for (int i=1; i<=ans[0]; ++i)
108             printf("%d ", ans[i]);
109     }
110 }
111 int main()
112 {
113     freopen("input.txt", "r", stdin);
114     freopen("output.txt", "w", stdout);
115     init();
116     solve();
117     return 0;
118 }
View Code

 

posted @ 2015-12-18 20:25  GerynOhenz  阅读(244)  评论(0编辑  收藏  举报