結果

問題 No.206 数の積集合を求めるクエリ
ユーザー startcppstartcpp
提出日時 2015-03-28 18:40:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,936 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 61,952 KB
実行使用メモリ 5,156 KB
最終ジャッジ日時 2023-09-11 10:49:07
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#define DB(x) 
using namespace std;

class AandBProblem {
private:
	int L, M, N;
	int A[100000], B[100000];
	int Q;

public:
	void input(int l, int m, int n, int *a, int *b, int q) {
		L = l;
		M = m;
		N = n;
		for(int i = 0; i < l; i++) A[i] = a[i];
		for(int i = 0; i < m; i++) B[i] = b[i];
		Q = q;
	}

	//O(N(L+M)Q)
	vector<int> solve1() {
		int i, j, k;
		vector<int> ret;
		ret.resize(Q);
		for( i = 0; i < Q; i++ ) {
			ret[i] = 0;
			for( j = 1; j <= N; j++ ) {
				for( k = 0; k < L; k++ )
					if ( A[k] == j ) break;
				if ( k == L ) continue;
				for( k = 0; k < M; k++ )
					if ( B[k] + i == j ) break;
				if ( k == M ) continue;
				ret[i]++;
			}
		}
		return ret;
	}
	//O(NQ)の定数1なやつ。
	vector<int> solve2() {
		int i, j;
		vector<int> ret;
		ret.resize(Q);
		for( i = 0; i < Q; i++ ) {
			ret[i] = 0;
			vector<int> paket;
			paket.resize(N+1+i);
			for( j = 0; j < N+1+i; j++ ) paket[j] = 0;
			
			for( j = 0; j < L; j++ ) {
				paket[A[j]]++;
			}
			for( j = 0; j < M; j++ ) {
				paket[B[j]+i]++;
			}

			for( j = 0; j < N+1; j++ ) {
				if ( paket[j] == 2 )
					ret[i]++;
			}
		}
		return ret;
	}

	//O(LM)の定数ちょっと速いやつ
	vector<int> solve3() {
		int i, j;
		int ans[100001] = {0};
		sort(A, A+L);
		sort(B, B+M);

		for( i = 0; i < L; i++ ) {
			for( j = 0; j < M; j++ ) {
				if ( B[j] > A[i] ) break;
				ans[ A[i] - B[j] ]++;
			}
		}

		vector<int> ret;
		for( i = 0; i < Q; i++ )
			ret.push_back(ans[i]);
		return ret;
	}

}test;

int L, M, N;
int A[100000], B[100000];
int Q;

int main() {
	scanf("%d%d%d", &L, &M, &N);
	for(int i = 0; i < L; i++ ) scanf("%d", A+i);
	for(int i = 0; i < M; i++ ) scanf("%d", B+i);
	scanf("%d", &Q);
	test.input(L, M, N, A, B, Q);

	printf("Test\n");

	//vector<int> res3 = test.solve3();
	//for(int i = 0; i < Q; i++ )
	//	printf("%d\n", res3[i]);
	return 0;
}
0