結果

問題 No.206 数の積集合を求めるクエリ
ユーザー utsumi_pgutsumi_pg
提出日時 2021-02-12 06:23:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,700 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 85,272 KB
実行使用メモリ 33,452 KB
最終ジャッジ日時 2023-09-25 20:59:51
合計ジャッジ時間 11,470 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,504 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 16 ms
4,380 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 567 ms
33,228 KB
testcase_18 AC 567 ms
33,284 KB
testcase_19 AC 574 ms
33,236 KB
testcase_20 AC 570 ms
33,280 KB
testcase_21 AC 569 ms
33,276 KB
testcase_22 AC 573 ms
33,276 KB
testcase_23 AC 574 ms
33,248 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <complex>
#include <cmath>
using namespace std;
 
int L, M, N;
int Q;
 
vector<complex<double>> DFT(vector<complex<double>> f, bool inverse){
	if(f.size() == 1) return f;
	vector<complex<double>> va, vb;
	for(int i = 0; i < f.size(); i++){
		if(i % 2 == 0) va.push_back(f[i]);
		else vb.push_back(f[i]);
	}
	va = DFT(va, inverse);
	vb = DFT(vb, inverse);
	double c = inverse ? 1.0 : -1.0;
	complex<double> cur = complex<double>(1.0, 0.0);
	complex<double> zeta = polar(1.0, c * acos(0.0) * 4.0 / (double)f.size());
	vector<complex<double>> res;
	for(int i = 0; i < f.size(); i++){
		res.push_back(va[i % (f.size() / 2)] + cur * vb[i % (f.size() / 2)]);
		cur *= zeta;
	}
	return res;
 
}
 
vector<double> FFT(vector<double> f, vector<double> g){
	vector<complex<double>> cf, cg;
	int n = 1;
	for(;;){
		if(n >= f.size() + g.size()) break;
		n *= 2;
	}
	cf.resize(n);
	cg.resize(n);
	for(int i = 0; i < f.size(); i++) cf[i] = complex<double>(f[i], 0.0);
	for(int i = 0; i < g.size(); i++) cg[i] = complex<double>(g[i], 0.0);
	cf = DFT(cf, true);
	cg = DFT(cg, true);
	for(int i = 0; i < n; i++) cf[i] *= cg[i];
	cf = DFT(cf, false);
	vector<double> res;
	for(int i = 0; i < n; i++) res.push_back(cf[i].real() / (double)n);
	return res;
}
 
int main(){
	scanf("%d %d %d", &L, &M, &N);
	vector<double> va(N), vb(N);
	for(int i = 0; i < L; i++){
		int a;
		scanf("%d", &a);
		a--;
		va[a] += 1.0;
	}
	for(int i = 0; i < M; i++){
		int a;
		scanf("%d", &a);
		a--;
		vb[N - a - 1] += 1.0;
	}
	vector<double> c = FFT(va, vb);
	scanf("%d", &Q);
	for(int i = 0; i < Q; i++) printf("%d%c", (int)floor(c[i + N - 1] + 0.0001), i == Q - 1 ? '\n' : ' ');
	return 0;
}
0