Submission #544670

# Submission time Handle Problem Language Result Execution time Memory
544670 2022-04-02T14:19:52 Z pokmui9909 None (KOI18_watertank) C++17
100 / 100
523 ms 44060 KB
#include <bits/stdc++.h>
using namespace std;

int N, M, H;
int A[1005][1005][5];
int W[1005][1005];
int xdir[4] = { -1, 0, 1, 0 };
int ydir[4] = { 0, 1, 0, -1 };

struct info
{
	int x, y, h;
};

struct cmp
{
	bool operator()(info a, info b)
	{
		return a.h > b.h;
	}
};

priority_queue<info, vector<info>, cmp> pq;

signed main()
{
	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N >> M >> H;
	for (int i = 1; i <= N + 1; i++)
	{
		for (int j = 1; j <= M; j++)
		{
			int K; cin >> K;
			A[i - 1][j][2] = A[i][j][0] = K;
		}
	}
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= M + 1; j++)
		{
			int K; cin >> K;
			A[i][j - 1][1] = A[i][j][3] = K;
		}
	}
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= M; j++)
			W[i][j] = H;
	}
	for (int i = 1; i <= M; i++)
	{
		if (A[1][i][0] != -1 && W[1][i] >= A[1][i][0])
		{
			W[1][i] = A[1][i][0];
			pq.push({ 1, i, A[1][i][0] });
		}
		if (A[N][i][2] != -1 && W[N][i] >= A[N][i][2])
		{ 
			W[N][i] = A[N][i][2]; 
			pq.push({ N, i, A[N][i][2] }); 
		}
	}
	for (int i = 1; i <= N; i++)
	{
		if (A[i][1][3] != -1 && W[i][1] >= A[i][1][3])
		{ 
			W[i][1] = A[i][1][3];
			pq.push({ i, 1, A[i][1][3] }); 
		}
		if (A[i][M][1] != -1 && W[i][M] >= A[i][M][1])
		{ 
			W[i][M] = A[i][M][1]; 
			pq.push({ i, M, A[i][M][1] });
		}
	}
	while (!pq.empty())
	{
		int x = pq.top().x, y = pq.top().y, h = pq.top().h; pq.pop();
		if (h != W[x][y]) continue;
		for (int i = 0; i < 4; i++)
		{
			if (A[x][y][i] == -1) continue;
			int nx = x + xdir[i], ny = y + ydir[i];
			if (nx < 1 || nx > N || ny < 1 || ny > M) continue;
			int nh = max(min(A[x][y][i], W[nx][ny]), W[x][y]);
			if (W[nx][ny] <= nh) continue;
			W[nx][ny] = nh;
			pq.push({ nx, ny, nh });
		}
	}
	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= M; j++)
			ans += W[i][j];
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 388 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 328 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 29752 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 101 ms 26824 KB Output is correct
4 Correct 104 ms 27100 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 188 ms 28948 KB Output is correct
7 Correct 103 ms 27432 KB Output is correct
8 Correct 265 ms 34252 KB Output is correct
9 Correct 97 ms 26548 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 237 ms 29412 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 732 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 2 ms 828 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 840 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 114 ms 29824 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 102 ms 28808 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 116 ms 29796 KB Output is correct
13 Correct 100 ms 26828 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 119 ms 27088 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 109 ms 27140 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 518 ms 44060 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 206 ms 30796 KB Output is correct
29 Correct 202 ms 28972 KB Output is correct
30 Correct 102 ms 27356 KB Output is correct
31 Correct 265 ms 34096 KB Output is correct
32 Correct 117 ms 29028 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 100 ms 26584 KB Output is correct
35 Correct 1 ms 724 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 239 ms 29412 KB Output is correct
39 Correct 523 ms 42124 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 724 KB Output is correct
42 Correct 1 ms 724 KB Output is correct
43 Correct 2 ms 852 KB Output is correct
44 Correct 111 ms 28360 KB Output is correct
45 Correct 390 ms 36412 KB Output is correct
46 Correct 0 ms 340 KB Output is correct