답안 #709894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709894 2023-03-14T18:42:36 Z rainboy Sandcastle 2 (JOI22_ho_t5) C
71 / 100
5000 ms 3276 KB
#include <stdio.h>
#include <string.h>

#define NM	50000

int di[] = { -1, 1, 0, 0 };
int dj[] = { 0, 0, -1, 1 };

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

int aa[NM], bb[NM], dd[NM], bad[3][3][3][3][NM], cc[3][3][NM], n, m;

int count(int il, int ir, int j, int y, int z) {
	int i, w, x, cnt;

	if (ir - il < 3) {
		cnt = 0;
		for (i = il; i <= ir; i++) {
			w = min(i - il, 2), x = min(ir - i, 2);
			if (bad[w][x][y][z][i * m + j])
				cnt++;
		}
	} else {
		cnt = 0;
		for (i = il; i < il + 2; i++)
			if (bad[i - il][2][y][z][i * m + j])
				cnt++;
		for (i = ir - 1; i <= ir; i++)
			if (bad[2][ir - i][y][z][i * m + j])
				cnt++;
		cnt += cc[y][z][(ir - 2) * m + j] - cc[y][z][(il + 1) * m + j];
	}
	return cnt;
}

int main() {
	static int dp[3][3][2], dq[3][3][2];
	int h, i, j, i_, j_, il, jl, ir, jr, ij, ij_, ij1, w, x, y, y_, z, z_, c, c_, tmp, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &aa[i * m + j]);
	if (n > m) {
		for (ij = 0; ij < n * m; ij++) {
			i = ij / m, j = ij % m;
			bb[j * n + i] = aa[i * m + j];
		}
		tmp = n, n = m, m = tmp;
		memcpy(aa, bb, n * m * sizeof *bb);
	}
	for (il = 0; il < n; il++)
		for (ir = il; ir < n && ir < il + 5; ir++)
			for (jl = 0; jl < m; jl++)
				for (jr = 0; jr < m && jr < jl + 5; jr++) {
					for (i = il; i <= ir; i++)
						for (j = jl; j <= jr; j++)
							dd[i * m + j] = 0;
					for (i = il; i <= ir; i++)
						for (j = jl; j <= jr; j++) {
							ij = i * m + j, ij1 = -1;
							for (h = 0; h < 4; h++) {
								i_ = i + di[h], j_ = j + dj[h];
								if (i_ >= il && i_ <= ir && j_ >= jl && j_ <= jr) {
									ij_ = i_ * m + j_;
									if (aa[ij_] < aa[ij] && (ij1 == -1 || aa[ij1] < aa[ij_]))
										ij1 = ij_;
								}
							}
							if (ij1 != -1)
								dd[ij1]++;
						}
					for (i = il; i <= ir; i++)
						for (j = jl; j <= jr; j++) {
							ij = i * m + j;
							if (dd[ij] != 1) {
								w = min(i - il, 2), x = min(ir - i, 2), y = min(j - jl, 2), z = min(jr - j, 2);
								bad[w][x][y][z][ij] = 1;
								if (w == 2 && x == 2)
									cc[y][z][ij] = 1;
							}
						}
				}
	for (y = 0; y < 3; y++)
		for (z = 0; z < 3; z++)
			for (ij = m; ij < n * m; ij++)
				cc[y][z][ij] += cc[y][z][ij - m];
	ans = 0;
	for (il = 0; il < n; il++)
		for (ir = il; ir < n; ir++) {
			memset(dp, 0, sizeof dp);
			for (j = 0; j < m; j++) {
				memset(dq, 0, sizeof dq);
				c = count(il, ir, j, 0, 0);
				if (c < 2)
					dq[0][0][c]++;
				c = count(il, ir, j, 0, 1);
				if (c < 2)
					dq[0][1][c]++;
				c = count(il, ir, j, 0, 2);
				if (c < 2)
					dq[0][2][c]++;
				for (y = 0; y < 3; y++)
					for (z = 0; z < 3; z++)
						for (c = 0; c < 2; c++) {
							int v = dp[y][z][c];

							if (v == 0)
								continue;
							if (z > 0) {
								y_ = min(y + 1, 2), z_ = z - 1, c_ = c + count(il, ir, j, y_, z_);
								if (c_ < 2)
									dq[y_][z_][c_] += v;
							}
							if (z == 2) {
								y_ = min(y + 1, 2), z_ = z, c_ = c + count(il, ir, j, y_, z_);
								if (c_ < 2)
									dq[y_][z_][c_] += v;
							}
						}
				memcpy(dp, dq, sizeof dq);
				ans += dp[0][0][1] + dp[1][0][1] + dp[2][0][1];
			}
		}
	printf("%d\n", ans);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:43:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |    scanf("%d", &aa[i * m + j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 5071 ms 1540 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 7 ms 412 KB Output is correct
9 Correct 13 ms 1140 KB Output is correct
10 Correct 11 ms 576 KB Output is correct
11 Correct 7 ms 400 KB Output is correct
12 Correct 8 ms 468 KB Output is correct
13 Correct 10 ms 1124 KB Output is correct
14 Correct 13 ms 948 KB Output is correct
15 Correct 14 ms 1208 KB Output is correct
16 Correct 16 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 7 ms 412 KB Output is correct
9 Correct 13 ms 1140 KB Output is correct
10 Correct 11 ms 576 KB Output is correct
11 Correct 7 ms 400 KB Output is correct
12 Correct 8 ms 468 KB Output is correct
13 Correct 10 ms 1124 KB Output is correct
14 Correct 13 ms 948 KB Output is correct
15 Correct 14 ms 1208 KB Output is correct
16 Correct 16 ms 1108 KB Output is correct
17 Correct 148 ms 520 KB Output is correct
18 Correct 91 ms 3168 KB Output is correct
19 Correct 145 ms 2840 KB Output is correct
20 Correct 107 ms 1148 KB Output is correct
21 Correct 65 ms 1676 KB Output is correct
22 Correct 62 ms 2992 KB Output is correct
23 Correct 73 ms 2920 KB Output is correct
24 Correct 73 ms 2508 KB Output is correct
25 Correct 83 ms 3104 KB Output is correct
26 Correct 77 ms 3276 KB Output is correct
27 Correct 90 ms 3072 KB Output is correct
28 Correct 84 ms 3052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 7 ms 412 KB Output is correct
9 Correct 13 ms 1140 KB Output is correct
10 Correct 11 ms 576 KB Output is correct
11 Correct 7 ms 400 KB Output is correct
12 Correct 8 ms 468 KB Output is correct
13 Correct 10 ms 1124 KB Output is correct
14 Correct 13 ms 948 KB Output is correct
15 Correct 14 ms 1208 KB Output is correct
16 Correct 16 ms 1108 KB Output is correct
17 Correct 148 ms 520 KB Output is correct
18 Correct 91 ms 3168 KB Output is correct
19 Correct 145 ms 2840 KB Output is correct
20 Correct 107 ms 1148 KB Output is correct
21 Correct 65 ms 1676 KB Output is correct
22 Correct 62 ms 2992 KB Output is correct
23 Correct 73 ms 2920 KB Output is correct
24 Correct 73 ms 2508 KB Output is correct
25 Correct 83 ms 3104 KB Output is correct
26 Correct 77 ms 3276 KB Output is correct
27 Correct 90 ms 3072 KB Output is correct
28 Correct 84 ms 3052 KB Output is correct
29 Execution timed out 5024 ms 1760 KB Time limit exceeded
30 Halted 0 ms 0 KB -