結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tempura_pptempura_pp
提出日時 2018-06-24 18:14:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 578 ms / 7,000 ms
コード長 1,986 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 96,044 KB
実行使用メモリ 36,424 KB
最終ジャッジ日時 2023-09-13 13:44:23
合計ジャッジ時間 9,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 12 ms
4,376 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 16 ms
4,476 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 16 ms
4,396 KB
testcase_17 AC 449 ms
35,812 KB
testcase_18 AC 421 ms
36,160 KB
testcase_19 AC 444 ms
35,852 KB
testcase_20 AC 422 ms
36,248 KB
testcase_21 AC 431 ms
36,332 KB
testcase_22 AC 428 ms
36,332 KB
testcase_23 AC 444 ms
36,400 KB
testcase_24 AC 578 ms
35,948 KB
testcase_25 AC 577 ms
36,120 KB
testcase_26 AC 559 ms
36,212 KB
testcase_27 AC 519 ms
36,424 KB
testcase_28 AC 572 ms
35,768 KB
testcase_29 AC 570 ms
36,060 KB
testcase_30 AC 559 ms
36,068 KB
権限があれば一括ダウンロードができます

ソースコード

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;
int sz;
double pi=3.14159265358979;

poly dft(poly f,int n){
    if(n==1)return f;
    poly g[2];
    rep(i,n/2){
        g[0].push_back(f[2*i]);
        g[1].push_back(f[2*i+1]);
    }
    g[0]=dft(g[0],n/2);
    g[1]=dft(g[1],n/2);
    complex<double> zeta=complex<double>(cos(2*pi/n),sin(2*pi/n));
    complex<double> ret=1;
    rep(i,n){
        f[i]=g[0][i%(n/2)]+ret*g[1][i%(n/2)];
        ret*=zeta;
    }
    return f;
}

poly rdft(poly f,int n){
    if(n==1)return f;
    poly g[2];
    rep(i,n/2){
        g[0].push_back(f[2*i]);
        g[1].push_back(f[2*i+1]);
    }
    g[0]=rdft(g[0],n/2);
    g[1]=rdft(g[1],n/2);
    complex<double> zeta=complex<double>(cos(2*pi/n),-sin(2*pi/n));
    complex<double> ret=1;
    rep(i,n){
        f[i]=g[0][i%(n/2)]+ret*g[1][i%(n/2)];
        ret*=zeta;
    }
    return f;
}

poly fft(poly g,poly h){
    poly f;
    int m=(int)g.size()+h.size()+1;
    sz=1;
    while(sz<m)sz*=2;
    f.resize(sz,0);
    g.resize(sz,0);
    h.resize(sz,0);
    g=dft(g,sz);
    h=dft(h,sz);
    rep(i,sz)f[i]=g[i]*h[i];
    f=rdft(f,sz);
    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);
    a.push_back(0);
    b.push_back(0);
    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)<<endl;
}
0