結果

問題 No.206 数の積集合を求めるクエリ
ユーザー FF256grhy
提出日時 2015-05-09 14:06:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,148 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 23,424 KB
実行使用メモリ 9,628 KB
最終ジャッジ日時 2024-07-05 21:12:49
合計ジャッジ時間 9,355 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 1 -- * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%d%d%d", &l, &m, &n);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:15:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         for(i = 0; i < l; i++) { scanf("%d", &a[i]); }
      |                                  ~~~~~^~~~~~~~~~~~~
main.cpp:16:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         for(i = 0; i < m; i++) { scanf("%d", &b[i]); }
      |                                  ~~~~~^~~~~~~~~~~~~
main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

//これ実質O(n^2)だし、さすがに通らないやろ…

#define MAX 100000

void marge_sort(int[], int, int);

int l, m, n, a[MAX], b[MAX], q;
int copy[MAX];

int main(void) {
	int i;
	scanf("%d%d%d", &l, &m, &n);
	for(i = 0; i < l; i++) { scanf("%d", &a[i]); }
	for(i = 0; i < m; i++) { scanf("%d", &b[i]); }
	scanf("%d", &q);
	
	marge_sort(a, 0, l - 1);
	marge_sort(b, 0, m - 1);
	
	for(i = 0; i < q; i++) {
		int pa = 0, pb = 0, cnt = 0;
		while(1) {
			if(a[pa] == b[pb] + i) { cnt++; }
			if(a[pa] <= b[pb] + i) { pa++; } else { pb++; }
			if(pa == l || pb == m) { break; }
		}
		printf("%d\n", cnt);
	}
	
	return 0;
}

void marge_sort(int x[], int l, int r) {
	if(l == r) { return; }
	int m = (l + r) / 2;
	marge_sort(x, l, m);
	marge_sort(x, m + 1, r);
	int p = l, q = m + 1, cnt = l;
	while(1) {
		int flag;
		if(m < p && r < q) { break; }
		else if(r < q) { flag = 1; }
		else if(m < p) { flag = 0; }
		else { flag = (x[p] <= x[q]); }
		if(flag) {
			copy[cnt] = x[p];
			p++;
			cnt++;
		} else {
			copy[cnt] = x[q];
			q++;
			cnt++;
		}
	}
	int i;
	for(i = l; i <= r; i++) {
		x[i] = copy[i];
	}
	return;
}
0