Submission #703032

# Submission time Handle Problem Language Result Execution time Memory
703032 2023-02-25T16:25:53 Z rainboy Hyper-minimum (IZhO11_hyper) C
100 / 100
360 ms 34596 KB
#include <stdio.h>
#include <string.h>

#define N	35

void solve(int *aa, int n, int m) {
	static int bb[N], qu[N];
	int i, head, cnt;

	for (i = 0, head = cnt = 0; i < n; i++) {
		while (cnt && aa[qu[head + cnt - 1]] >= aa[i])
			cnt--;
		qu[head + cnt++] = i;
		if (i >= m - 1) {
			bb[i - m + 1] = aa[qu[head]];
			if (qu[head] == i - m + 1)
				head++, cnt--;
		}
	}
	memcpy(aa, bb, (n - m + 1) * sizeof *bb);
}

int main() {
	static int aa[N][N][N][N], bb[N];
	int n, n_, m, i, j, k, l;

	scanf("%d%d", &n, &m), n_ = n - m + 1;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (k = 0; k < n; k++)
				for (l = 0; l < n; l++)
					scanf("%d", &aa[i][j][k][l]);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (k = 0; k < n; k++) {
				for (l = 0; l < n; l++)
					bb[l] = aa[i][j][k][l];
				solve(bb, n, m);
				for (l = 0; l < n_; l++)
					aa[i][j][k][l] = bb[l];
			}
	for (l = 0; l < n_; l++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++) {
				for (k = 0; k < n; k++)
					bb[k] = aa[i][j][k][l];
				solve(bb, n, m);
				for (k = 0; k < n_; k++)
					aa[i][j][k][l] = bb[k];
			}
	for (k = 0; k < n_; k++)
		for (l = 0; l < n_; l++)
			for (i = 0; i < n; i++) {
				for (j = 0; j < n; j++)
					bb[j] = aa[i][j][k][l];
				solve(bb, n, m);
				for (j = 0; j < n_; j++)
					aa[i][j][k][l] = bb[j];
			}
	for (j = 0; j < n_; j++)
		for (k = 0; k < n_; k++)
			for (l = 0; l < n_; l++) {
				for (i = 0; i < n; i++)
					bb[i] = aa[i][j][k][l];
				solve(bb, n, m);
				for (i = 0; i < n_; i++)
					aa[i][j][k][l] = bb[i];
			}
	for (i = 0; i < n_; i++)
		for (j = 0; j < n_; j++)
			for (k = 0; k < n_; k++)
				for (l = 0; l < n_; l++)
					printf("%d ", aa[i][j][k][l]);
	printf("\n");
	return 0;
}

Compilation message

hyper.c: In function 'main':
hyper.c:27:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%d%d", &n, &m), n_ = n - m + 1;
      |  ^~~~~~~~~~~~~~~~~~~~~
hyper.c:32:6: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |      scanf("%d", &aa[i][j][k][l]);
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 2 ms 832 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 10 ms 2048 KB Output is correct
7 Correct 10 ms 1860 KB Output is correct
8 Correct 24 ms 3752 KB Output is correct
9 Correct 38 ms 5444 KB Output is correct
10 Correct 25 ms 3892 KB Output is correct
11 Correct 87 ms 8012 KB Output is correct
12 Correct 132 ms 14024 KB Output is correct
13 Correct 112 ms 12852 KB Output is correct
14 Correct 181 ms 18784 KB Output is correct
15 Correct 282 ms 29192 KB Output is correct
16 Correct 195 ms 17824 KB Output is correct
17 Correct 193 ms 19120 KB Output is correct
18 Correct 360 ms 34596 KB Output is correct
19 Correct 289 ms 23604 KB Output is correct
20 Correct 207 ms 21428 KB Output is correct