Submission #469981

# Submission time Handle Problem Language Result Execution time Memory
469981 2021-09-02T13:36:44 Z rainboy Hokej (COCI17_hokej) C
0 / 120
212 ms 36004 KB
#include <stdio.h>

#define N	500000
#define M	500000

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

unsigned int X = 12345;

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

int aa[N], bb[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)
			if (aa[ii[j]] == aa[i_])
				j++;
			else if (aa[ii[j]] > aa[i_]) {
				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], ii_[M * 6];
	int n, m, h, i, j, k;
	long long ans;

	scanf("%d%d", &m, &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &aa[i], &bb[i]);
		ii[i] = i;
	}
	sort(ii, 0, n);
	ans = 0;
	for (i = 0, j = 0; i < n && j < m * 6; i++) {
		int i_ = ii[i];

		bb[i_] = min(bb[i_], m * 6 - j);
		ans += (long long) aa[i_] * bb[i_];
		j += bb[i_];
	}
	for (i = 0, j = 0; i < n; i++)
		if (bb[i] == m)
			while (bb[i]--)
				ii_[j++] = i;
	for (i = 0; i < n; i++)
		if (bb[i] > 0)
			while (bb[i]--)
				ii_[j++] = i;
	k = 0;
	for (j = 1; j < m; j++)
		for (h = 0; h < 6; h++)
			if (ii_[h * m + j] != ii_[h * m + j - 1])
				k++;
	printf("%lld\n", ans);
	for (h = 0; h < 6; h++)
		printf("%d ", ii_[h * m + 0] + 1);
	printf("\n");
	printf("%d\n", k);
	for (j = 1; j < m; j++)
		for (h = 0; h < 6; h++)
			if (ii_[h * m + j] != ii_[h * m + j - 1])
				printf("%d %d %d\n", j, ii_[h * m + j - 1] + 1, ii_[h * m + j] + 1);
	return 0;
}

Compilation message

hokej.c: In function 'main':
hokej.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%d", &m, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~
hokej.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d%d", &aa[i], &bb[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Failed 0 ms 204 KB the answer doesn't match with the value Z
2 Failed 4 ms 3532 KB the answer doesn't match with the value Z
3 Runtime error 29 ms 28468 KB Execution killed with signal 11
4 Failed 1 ms 460 KB the answer doesn't match with the value Z
5 Runtime error 24 ms 28284 KB Execution killed with signal 11
6 Failed 2 ms 332 KB the answer doesn't match with the value Z
7 Failed 4 ms 1176 KB the answer doesn't match with the value Z
8 Runtime error 52 ms 29636 KB Execution killed with signal 11
9 Runtime error 209 ms 35984 KB Execution killed with signal 11
10 Runtime error 212 ms 36004 KB Execution killed with signal 11