답안 #829381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829381 2023-08-18T10:00:07 Z rainboy Topical (NOI23_topical) C
100 / 100
332 ms 58776 KB
#include <stdio.h>

#define N	1000000
#define M	1000000

unsigned int X = 12345;

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

int *vv;

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 (vv[ii[j]] == vv[i_])
				j++;
			else if (vv[ii[j]] < vv[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 mem[N * 3], *ptr = mem;
	static int *aa[M], *bb[M], *ii[M], hh[M], dd[N], qu[N];
	static long long cc[M];
	int n, m, cnt, h, i, j;

	scanf("%d%d", &n, &m);
	for (j = 0; j < m; j++) {
		aa[j] = ptr, ptr += n;
		bb[j] = ptr, ptr += n;
		ii[j] = ptr, ptr += n;
	}
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &aa[j][i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &bb[j][i]);
	for (j = 0; j < m; j++) {
		for (i = 0; i < n; i++)
			ii[j][i] = i;
		vv = aa[j], sort(ii[j], 0, n);
	}
	for (i = 0; i < n; i++)
		dd[i] = m;
	cnt = 0;
	for (j = 0; j < m; j++)
		while (hh[j] < n && aa[j][i = ii[j][hh[j]]] <= cc[j]) {
			if (--dd[i] == 0)
				qu[cnt++] = i;
			hh[j]++;
		}
	for (h = 0; h < cnt; h++) {
		i = qu[h];
		for (j = 0; j < m; j++)
			cc[j] += bb[j][i];
		for (j = 0; j < m; j++)
			while (hh[j] < n && aa[j][i = ii[j][hh[j]]] <= cc[j]) {
				if (--dd[i] == 0)
					qu[cnt++] = i;
				hh[j]++;
			}
	}
	printf("%d\n", cnt);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:47:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |    scanf("%d", &aa[j][i]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
Main.c:50:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |    scanf("%d", &bb[j][i]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 174 ms 58776 KB Output is correct
5 Correct 184 ms 58776 KB Output is correct
6 Correct 178 ms 58776 KB Output is correct
7 Correct 142 ms 41276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 30 ms 3588 KB Output is correct
5 Correct 28 ms 3376 KB Output is correct
6 Correct 332 ms 34708 KB Output is correct
7 Correct 314 ms 32444 KB Output is correct
8 Correct 329 ms 34676 KB Output is correct
9 Correct 326 ms 32612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 174 ms 58776 KB Output is correct
5 Correct 184 ms 58776 KB Output is correct
6 Correct 178 ms 58776 KB Output is correct
7 Correct 142 ms 41276 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 4 ms 596 KB Output is correct
23 Correct 30 ms 3588 KB Output is correct
24 Correct 28 ms 3376 KB Output is correct
25 Correct 332 ms 34708 KB Output is correct
26 Correct 314 ms 32444 KB Output is correct
27 Correct 329 ms 34676 KB Output is correct
28 Correct 326 ms 32612 KB Output is correct
29 Correct 235 ms 30304 KB Output is correct
30 Correct 262 ms 29304 KB Output is correct
31 Correct 292 ms 27732 KB Output is correct
32 Correct 170 ms 21208 KB Output is correct
33 Correct 208 ms 22104 KB Output is correct
34 Correct 205 ms 21956 KB Output is correct
35 Correct 264 ms 24288 KB Output is correct
36 Correct 255 ms 25108 KB Output is correct
37 Correct 266 ms 27780 KB Output is correct
38 Correct 128 ms 16716 KB Output is correct