結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー betit0919betit0919
提出日時 2020-05-29 22:43:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,675 bytes
コンパイル時間 1,325 ms
コンパイル使用メモリ 116,272 KB
実行使用メモリ 598,876 KB
最終ジャッジ日時 2024-04-24 00:09:18
合計ジャッジ時間 6,778 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;
typedef vector<complex<long double>> poly;
const long double pi=acos(-1);

poly dft(poly f,int rev){
  int n=f.size();
  int j=0;
  REP(i,1,n-1){
      for(int k=n/2;k>(j^=k);k>>=1);
      if(i<j)swap(f[i],f[j]);
  }
  complex<long double> zeta,ret,t,s;
  for(int i=1;i<n;i<<=1){
    zeta=polar((long double)1.0,pi/i*rev);
    for(int j=0;j<n;j+=2*i){
      ret=1;
      rep(k,i){
        s=f[j+k];
        t=f[j+k+i];
        t=complex<long double>(t.real()*ret.real()-t.imag()*ret.imag(),t.imag()*ret.real()+t.real()*ret.imag());
        f[j+k]=s+t;
        f[j+k+i]=s-t;
        ret*=zeta;
      }
    }
  }
  if(rev==-1)rep(i,n)f[i]/=n;
  return f;
}

poly fft(poly g,poly h){
   poly f;
   int m=(int)g.size()+h.size()+1;
   int sz=1;
   while(sz<m)sz*=2;
   f.resize(sz,0);
   g.resize(sz,0);
   h.resize(sz,0);
   g=dft(g,1);
   h=dft(h,1);
   rep(i,sz)f[i]=g[i]*h[i];
   f=dft(f,-1);
   return f;
}
int main(){
    poly a;
    a.resize(1);
    a[0]=1;

    int N,Q;
    cin>>N>>Q;
    rep(i,N){
      int x;cin>>x;
      poly b;
      b.resize(2);
      b[0]=1;
      b[1]=x-1;
      a=fft(a,b);
    }
    rep(i,Q){
      int x;cin>>x;
      cout<<(int)(a[N-x].real()+0.5)%mod<<endl;
    }
}
0