답안 #730929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730929 2023-04-26T15:52:16 Z rainboy 움직이는 개미 (IZhO12_ants) C
100 / 100
1 ms 292 KB
#include <stdio.h>

#define N	100

unsigned int Z = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

int xx[N], yy[N], dd[N], xx_[N], yy_[N], dd_[N];

int compare_xy(int i, int j) { return xx[i] != xx[j] ? xx[i] - xx[j] : yy[i] - yy[j]; }
int compare_yx(int i, int j) { return yy[i] != yy[j] ? yy[i] - yy[j] : xx[i] - xx[j]; }
int compare_xd(int i, int j) { return xx_[i] != xx_[j] ? xx_[i] - xx_[j] : dd_[j] - dd_[i]; }
int compare_yd(int i, int j) { return yy_[i] != yy_[j] ? yy_[i] - yy_[j] : dd_[j] - dd_[i]; }

int (*compare)(int, int);

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = compare(ii[j], i_);

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

void solve_x(int *ii, int n, int x_, int t) {
	static int ii_[N];
	int h, i, i_, x;

	for (h = 0; h < n; h++) {
		i = ii[h], x = ((dd[i] == 0 ? xx[i] : x_ * 2 - xx[i]) + t) % (x_ * 2);
		if (x < x_)
			xx_[h] = x, dd_[h] = 0;
		else
			xx_[h] = x_ * 2 - x, dd_[h] = 2;
	}
	for (i = 0; i < n; i++)
		ii_[i] = i;
	compare = compare_xd, sort(ii_, 0, n);
	for (h = 0; h < n; h++) {
		i = ii[h], i_ = ii_[h];
		xx[i] = xx_[i_], dd[i] = dd_[i_];
	}
}

void solve_y(int *ii, int n, int y_, int t) {
	static int ii_[N];
	int h, i, i_, y;

	for (h = 0; h < n; h++) {
		i = ii[h], y = ((dd[i] == 1 ? yy[i] : y_ * 2 - yy[i]) + t) % (y_ * 2);
		if (y < y_)
			yy_[h] = y, dd_[h] = 1;
		else
			yy_[h] = y_ * 2 - y, dd_[h] = 3;
	}
	for (i = 0; i < n; i++)
		ii_[i] = i;
	compare = compare_yd, sort(ii_, 0, n);
	for (h = 0; h < n; h++) {
		i = ii[h], i_ = ii_[h];
		yy[i] = yy_[i_], dd[i] = dd_[i_];
	}
}

int main() {
	static int ii[N];
	int n, n_, x_, y_, t, i, j;

	scanf("%d%d%d%d", &x_, &y_, &n, &t);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &xx[i], &yy[i], &dd[i]), dd[i]--;
	n_ = 0;
	for (i = 0; i < n; i++)
		if (dd[i] % 2 == 0)
			ii[n_++] = i;
	compare = compare_yx, sort(ii, 0, n_);
	for (i = 0; i < n_; i = j) {
		j = i + 1;
		while (j < n_ && yy[ii[j]] == yy[ii[i]])
			j++;
		solve_x(ii + i, j - i, x_, t);
	}
	n_ = 0;
	for (i = 0; i < n; i++)
		if (dd[i] % 2 != 0)
			ii[n_++] = i;
	compare = compare_xy, sort(ii, 0, n_);
	for (i = 0; i < n_; i = j) {
		j = i + 1;
		while (j < n_ && xx[ii[j]] == xx[ii[i]])
			j++;
		solve_y(ii + i, j - i, y_, t);
	}
	for (i = 0; i < n; i++)
		printf("%d %d %d\n", xx[i], yy[i], dd[i] + 1);
	return 0;
}

Compilation message

ants.c: In function 'main':
ants.c:86:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |  scanf("%d%d%d%d", &x_, &y_, &n, &t);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ants.c:88:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   scanf("%d%d%d", &xx[i], &yy[i], &dd[i]), dd[i]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 284 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 288 KB Output is correct
15 Correct 0 ms 288 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct