Submission #752317

# Submission time Handle Problem Language Result Execution time Memory
752317 2023-06-02T18:16:12 Z gnu Dijamant (COCI22_dijamant) C++14
70 / 70
226 ms 104896 KB
#include <iostream>
#include <vector>
using namespace std;


vector<vector<long long>> pref;
long long get(int i, int l, int r)
{
	return pref[i][r+1] - pref[i][l];
}
int main()
{
	int n, m; cin >> n >> m;
	vector<string> mat(n);
	for (auto& x : mat) cin >> x;
	vector<vector<int>> a, b, c, d;
	a = b = c = d = vector<vector<int>>(n, vector<int>(m, -1));
	pref = vector<vector<long long>>(n, vector<long long>(m + 1));
	for (int i = 0; i < n; ++i) {
		for (int j = 1; j <= m; ++j) {
			pref[i][j] = pref[i][j - 1] + (mat[i][j - 1] == '#');
		}
	}
	//cout << get(2, 1, 6) << '\n';
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (i > 0 && j + 2 < m) {
				if (mat[i][j] == '#' && mat[i][j + 1] == '.' && mat[i][j + 2] == '#' && mat[i - 1][j + 1] == '#') a[i][j] = 1, b[i][j + 2] = 1;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (mat[i][j] != '#') continue;
			int x1 = j;
			++j;
			for (; j < m; ++j) {
				if (mat[i][j] == '#') break;
			}
			//cout << i << ' ' << j << '\n';
			if (j == m || i == 0 || x1 + 1 >= m || j==0) continue;
			if (a[i - 1][x1 + 1] == 1 && b[i - 1][j - 1] == 1 && get(i-1, x1+1, j-1) == 2) a[i][x1] = 1, b[i][j] = 1;
			--j;
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {

			if (i + 1 < n && j + 2 < m) {
				if (mat[i][j] == '#' && mat[i][j + 1] == '.' && mat[i][j + 2] == '#' && mat[i + 1][j + 1] == '#') c[i][j] = 1, d[i][j + 2] = 1;
			}
		}
	}

	for (int i = n-1; i > 0; --i) {
		for (int j = 0; j < m; ++j) {
			if (mat[i][j] != '#') continue;
			int x1 = j;
			++j;
			for (; j < m; ++j) {
				if (mat[i][j] == '#') break;
			}
			if (j == m || i == n-1 || x1 + 1 >= m || j == 0) continue;
			if (c[i + 1][x1 + 1] == 1 && d[i + 1][j - 1] == 1 && get(i+1, x1+1, j-1) == 2) c[i][x1] = 1, d[i][j] = 1;
			--j;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (mat[i][j] != '#') continue;
			int x1 = j;
			++j;
			for (; j < m; ++j) {
				if (mat[i][j] == '#') break;
			}
			if (j == m) continue;
			if (a[i][x1] == 1 && b[i][j] == 1 && c[i][x1] == 1 && d[i][j] == 1) ++ans;
			--j;
		}
	}
	cout << ans << '\n';
	return 0;


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 137 ms 94064 KB Output is correct
15 Correct 160 ms 99964 KB Output is correct
16 Correct 226 ms 89088 KB Output is correct
17 Correct 152 ms 89040 KB Output is correct
18 Correct 202 ms 104896 KB Output is correct
19 Correct 137 ms 85924 KB Output is correct
20 Correct 162 ms 104468 KB Output is correct
21 Correct 148 ms 86160 KB Output is correct
22 Correct 181 ms 91496 KB Output is correct
23 Correct 168 ms 86604 KB Output is correct
24 Correct 181 ms 93412 KB Output is correct
25 Correct 121 ms 85580 KB Output is correct
26 Correct 163 ms 88700 KB Output is correct