Submission #895272

#TimeUsernameProblemLanguageResultExecution timeMemory
895272rainboy화살표 그리기 (KOI18_arrowH)C11
100 / 100
30 ms3160 KiB
#include <stdio.h>

#define N	100000
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }

unsigned int Z = 12345;

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

int cc[N], xx[N];

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 = cc[ii[j]] != cc[i_] ? cc[ii[j]] - cc[i_] : xx[ii[j]] - xx[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];
	int n, i, d;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &cc[i]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	sort(ii, 0, n);
	ans = 0;
	for (i = 0; i < n; i++) {
		d = INF;
		if (i > 0 && cc[ii[i]] == cc[ii[i - 1]])
			d = min(d, xx[ii[i]] - xx[ii[i - 1]]);
		if (i + 1 < n && cc[ii[i]] == cc[ii[i + 1]])
			d = min(d, xx[ii[i + 1]] - xx[ii[i]]);
		if (d != INF)
			ans += d;
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

arrow.c: In function 'main':
arrow.c:43:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
arrow.c:45:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d%d", &xx[i], &cc[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...