Submission #61139499


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int cmp(const void* x, const void* y) {
int a = *(const int*)x, b = *(const int*)y;
return a < b ? -1 : a > b;
}
/* arr query */
int meow(const int* arr, int arrSize, long long query) {
int l = 0,r = arrSize - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (arr[m] == query) return m;
else if (arr[m] < query) l = m + 1;
else r = m - 1;
}
return arrSize;
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

/* 昇順に並んだ arr から query を探す */
int meow(const int* arr, int arrSize, long long query) {
	int l = 0,r = arrSize - 1;
	while (l <= r) {
		int m = l + (r - l) / 2;
		if (arr[m] == query) return m;
		else if (arr[m] < query) l = m + 1;
		else r = m - 1;
	}
	return arrSize;
}

struct ie_s {
	int pos;
	int idx;
};

int cmp_ie(const void* x, const void* y) {
	struct ie_s a = *(const struct ie_s*)x, b = *(const struct ie_s*)y;
	return a.pos < b.pos ? -1 : a.pos > b.pos;
}

/* 昇順に並んだ arr の中で query 以上の最初の要素を探す */
int gorogoro(const struct ie_s* arr, int arrSize, long long query) {
	int no = 0, yes = arrSize - 1;
	if (arrSize <= 0 || arr[yes].pos < query) return arrSize;
	if (arr[no].pos >= query) return 0;
	while (no + 1 < yes) {
		int m = no + (yes - no) / 2;
		if (arr[m].pos >= query) yes = m; else no = m;
	}
	return yes;
}

/* 昇順に並んだ arr の中で query 超の最初の要素を探す */
int surisuri(const struct ie_s* arr, int arrSize, long long query) {
	int no = 0, yes = arrSize - 1;
	if (arrSize <= 0 || arr[yes].pos <= query) return arrSize;
	if (arr[no].pos > query) return 0;
	while (no + 1 < yes) {
		int m = no + (yes - no) / 2;
		if (arr[m].pos > query) yes = m; else no = m;
	}
	return yes;
}

int N, M, Sx, Sy;
int X[212345], Y[212345];
char D[212345];
int C[212345];

int Xlist[212345], Xnum;
int Ylist[212345], Ynum;

int tateNum[212345], yokoNum[212345];
struct ie_s *tate[212345], *yoko[212345];

int *tateImos[212345], *yokoImos[212345];

char visited[212345];

int main(void) {
	int i, j, ans;
	int64_t curx, cury;
	if (scanf("%d%d%d%d", &N, &M, &Sx, &Sy) != 4) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d%d", &X[i], &Y[i]) != 2) return 1;
		Xlist[i] = X[i];
		Ylist[i] = Y[i];
	}
	for (i = 0; i < M; i++) {
		char Dbuf[4];
		if (scanf("%3s%d", Dbuf, &C[i]) != 2) return 1;
		D[i] = *Dbuf;
	}

	/* 座標圧縮 */
	qsort(Xlist, N, sizeof(*Xlist), cmp);
	qsort(Ylist, N, sizeof(*Ylist), cmp);
	for (i = 1, Xnum = 1; i < N; i++) {
		if (Xlist[Xnum - 1] != Xlist[i]) Xlist[Xnum++] = Xlist[i];
	}
	for (i = 1, Ynum = 1; i < N; i++) {
		if (Ylist[Ynum - 1] != Ylist[i]) Ylist[Xnum++] = Ylist[i];
	}

	/* 家を行ごと・列ごとにまとめる */
	for (i = 0; i < N; i++) {
		int Xidx = meow(Xlist, Xnum, X[i]);
		int Yidx = meow(Ylist, Ynum, Y[i]);
		tate[Xidx] = realloc(tate[Xidx], sizeof(*tate[Xidx]) * (tateNum[Xidx] + 1));
		tate[Xidx][tateNum[Xidx]++] = (struct ie_s){ Y[i], i };
		yoko[Yidx] = realloc(yoko[Yidx], sizeof(*yoko[Yidx]) * (yokoNum[Yidx] + 1));
		yoko[Yidx][yokoNum[Yidx]++] = (struct ie_s){ X[i], i };
	}
	for (i = 0; i < Xnum; i++) {
		if (tateNum[i] > 0) {
			qsort(tate[i], tateNum[i], sizeof(*tate[i]), cmp_ie);
			tateImos[i] = calloc(tateNum[i] + 1, sizeof(*tateImos[i]));
		}
	}
	for (i = 0; i < Ynum; i++) {
		if (yokoNum[i] > 0) {
			qsort(yoko[i], yokoNum[i], sizeof(*yoko[i]), cmp_ie);
			yokoImos[i] = calloc(yokoNum[i] + 1, sizeof(*yokoImos[i]));
		}
	}

	/* それぞれの線分について、通る家をいもす法でマーク */
	for (curx = Sx, cury = Sy, i = 0; i < M; i++) {
		int64_t select = 0, start = 0, end = 0;
		int type = 0;
		switch (D[i]) {
			case 'U':
				type = 1;
				select = curx;
				start = cury;
				end = cury + C[i];
				cury += C[i];
				break;
			case 'D':
				type = 1;
				select = curx;
				start = cury - C[i];
				end = cury;
				cury -= C[i];
				break;
			case 'L':
				type = 2;
				select = cury;
				start = curx - C[i];
				end = curx;
				curx -= C[i];
				break;
			case 'R':
				type = 2;
				select = cury;
				start = curx;
				end = curx + C[i];
				curx += C[i];
				break;
		}
		if (type == 1) {
			int idx = meow(Xlist, Xnum, select);
			if (idx < Xnum && tateNum[idx] > 0) {
				int startIdx = gorogoro(tate[idx], tateNum[idx], start);
				int endIdx = surisuri(tate[idx], tateNum[idx], end);
				tateImos[idx][startIdx]++;
				tateImos[idx][endIdx]--;
			}
		} else if (type == 2) {
			int idx = meow(Ylist, Ynum, select);
			if (idx < Ynum && yokoNum[idx] > 0) {
				int startIdx = gorogoro(yoko[idx], yokoNum[idx], start);
				int endIdx = surisuri(yoko[idx], yokoNum[idx], end);
				yokoImos[idx][startIdx]++;
				yokoImos[idx][endIdx]--;
			}
		}
	}

	/* 通る家にフラグを立てて数える */
	for (i = 0; i < Xnum; i++) {
		for (j = 0; j < tateNum[i]; j++) {
			if (tateImos[i][j]) visited[tate[i][j].idx] = 1;
			tateImos[i][j + 1] += tateImos[i][j];
		}
	}
	for (i = 0; i < Ynum; i++) {
		for (j = 0; j < yokoNum[i]; j++) {
			if (yokoImos[i][j]) visited[yoko[i][j].idx] = 1;
			yokoImos[i][j + 1] += yokoImos[i][j];
		}
	}
	for (i = 0, ans = 0; i < N; i++) {
		if (visited[i]) ans++;
	}
	printf("%" PRId64 " %" PRId64 " %d\n", curx, cury, ans);

	return 0;
}

/*

1. 家を行ごと・列ごとにまとめる
2. それぞれの線分について、通る家をいもす法でマーク
3. 通る家にフラグを立てて数える

*/

Submission Info

Submission Time
Task D - Santa Claus 2
User mikecat
Language C (gcc 12.2.0)
Score 0
Code Size 5322 Byte
Status RE
Exec Time 183 ms
Memory 16424 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 425
Status
AC × 2
AC × 11
WA × 12
RE × 2
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand.txt AC 1 ms 1748 KB
random_01.txt AC 20 ms 2716 KB
random_02.txt AC 19 ms 2780 KB
random_03.txt AC 19 ms 2724 KB
random_04.txt AC 91 ms 9936 KB
random_05.txt AC 92 ms 9728 KB
random_06.txt AC 67 ms 4980 KB
random_07.txt AC 91 ms 16424 KB
random_08.txt RE 183 ms 9156 KB
random_09.txt RE 172 ms 5880 KB
random_10.txt AC 43 ms 6300 KB
random_11.txt WA 126 ms 13420 KB
random_12.txt WA 147 ms 13860 KB
random_13.txt WA 116 ms 13348 KB
random_14.txt WA 121 ms 13744 KB
random_15.txt WA 145 ms 13928 KB
random_16.txt WA 158 ms 14100 KB
random_17.txt WA 146 ms 14064 KB
random_18.txt WA 117 ms 13884 KB
random_19.txt WA 148 ms 14052 KB
random_20.txt WA 122 ms 13320 KB
random_21.txt WA 140 ms 13880 KB
random_22.txt WA 130 ms 14176 KB
sample_01.txt AC 1 ms 1748 KB
sample_02.txt AC 1 ms 1804 KB


2024-12-28 (Sat)
18:33:04 +09:00