답안 #944536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944536 2024-03-12T22:13:35 Z rainboy 막대기 (KOI13_game) C
100 / 100
59 ms 4584 KB
#include <stdio.h>

#define N	100000

int abs_(int a) { return a > 0 ? a : -a; }
long long max(long long a, long long b) { return a > b ? a : b; }

unsigned int X = 12345;

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

int xx[N], yy[N], ww[N];

int compare_x(int i, int j) { return xx[i] - xx[j]; }
int compare_y(int i, int j) { return yy[i] - yy[j]; }
int compare_xy(int i, int j) { return xx[i] != xx[j] ? xx[i] - xx[j] : yy[i] - yy[j]; }

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;
	}
}

int main() {
	static int ii[N];
	static long long dpx[N], dpy[N];
	int n, l, h, i, x, y;
	long long zx, zy, ans;

	scanf("%d%d", &n, &l);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &xx[i], &yy[i]);
		ww[i] = abs_(xx[i] - yy[i]) + l;
	}
	for (i = 0; i < n; i++)
		ii[i] = i;
	compare = compare_x, sort(ii, 0, n);
	for (i = 0, x = 0; i < n; i++)
		xx[ii[i]] = i + 1 == n || xx[ii[i + 1]] != xx[ii[i]] ? x++ : x;
	compare = compare_y, sort(ii, 0, n);
	for (i = 0, y = 0; i < n; i++)
		yy[ii[i]] = i + 1 == n || yy[ii[i + 1]] != yy[ii[i]] ? y++ : y;
	compare = compare_xy, sort(ii, 0, n);
	ans = 0;
	for (h = 0; h < n; h++) {
		i = ii[h], x = xx[i], y = yy[i];
		zx = dpx[x] + ww[i], zy = dpy[y] + ww[i];
		ans = max(ans, max(zx, zy));
		dpy[y] = max(dpy[y], zx);
		dpx[x] = max(dpx[x], zy);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

game.c: In function 'main':
game.c:50:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%d%d", &n, &l);
      |  ^~~~~~~~~~~~~~~~~~~~~
game.c:52:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1112 KB Output is correct
2 Correct 21 ms 1628 KB Output is correct
3 Correct 46 ms 2648 KB Output is correct
4 Correct 43 ms 2840 KB Output is correct
5 Correct 45 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 5 ms 688 KB Output is correct
3 Correct 22 ms 2336 KB Output is correct
4 Correct 58 ms 3924 KB Output is correct
5 Correct 55 ms 3924 KB Output is correct
6 Correct 53 ms 4432 KB Output is correct
7 Correct 59 ms 4384 KB Output is correct
8 Correct 42 ms 4584 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 59 ms 3924 KB Output is correct
12 Correct 46 ms 4084 KB Output is correct