結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tempura_pptempura_pp
提出日時 2018-06-24 18:34:54
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,674 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 93,280 KB
実行使用メモリ 35,536 KB
最終ジャッジ日時 2023-09-13 13:45:17
合計ジャッジ時間 8,482 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 2 ms
4,380 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 11 ms
4,472 KB
testcase_16 RE -
testcase_17 WA -
testcase_18 AC 331 ms
35,352 KB
testcase_19 AC 349 ms
35,116 KB
testcase_20 AC 330 ms
35,192 KB
testcase_21 WA -
testcase_22 AC 335 ms
35,160 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 344 ms
35,252 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

typedef vector<complex<double>> poly;
const double pi=acos(-1);

poly dft(poly f,int n,bool rev){
    if(n==1)return f;
    poly g[2];
    rep(i,2)g[i].resize(n/2);
    rep(i,n/2){
        g[0][i]=f[2*i];
        g[1][i]=f[2*i+1];
    }
    g[0]=dft(g[0],n/2,rev);
    g[1]=dft(g[1],n/2,rev);
    complex<double> zeta=complex<double>(cos(2*pi/n),sin(2*pi/n));
    if(rev)zeta=1.0/zeta;
    complex<double> ret=1;
    rep(i,n/2){
        f[i]=g[0][i]+ret*g[1][i];
        ret*=zeta;
    }
    rep(i,n/2){
        f[i+n/2]=g[0][i]+ret*g[1][i];
        ret*=zeta;
    }
    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,sz,0);
    h=dft(h,sz,0);
    rep(i,sz)f[i]=g[i]*h[i];
    f=dft(f,sz,1);
    rep(i,sz)f[i]/=sz;
    return f;
}


int main(){
    int l,m,n;
    cin>>l>>m>>n;
    poly a,b;
    a.resize(n);
    b.resize(n);
    rep(i,l){
        int x;
        cin>>x;
        a[x]=1;

    }
    rep(i,m){
        int x;
        cin>>x;
        b[n-x]=1;

    }
    poly c=fft(a,b);
    int q;cin>>q;
    rep(i,q)cout<<(int)(c[n+i].real()+0.5)<<"\n";
}
0