Submission #880741

# Submission time Handle Problem Language Result Execution time Memory
880741 2023-11-30T01:01:03 Z tsumondai Dijamant (COCI22_dijamant) C++14
70 / 70
277 ms 241236 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 2e3 + 5;

const int oo = 1e9, mod = 1e9 + 7;

int n, m, sol;
char c[N][N];
bool bio[N][N];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int mn_sum, mx_sum, mn_dif, mx_dif, ok, cnt;

void dfs (int x, int y) {
	if (x == 0 || x == n + 1 || y == 0 || y == m + 1) {
		ok = 0;
		return;
	}
	if (bio[x][y] || c[x][y] == '#') return;
	bio[x][y] = 1;
	cnt++;

	mn_sum = min(mn_sum, x + y);
	mx_sum = max(mx_sum, x + y);
	mn_dif = min(mn_dif, x - y);
	mx_dif = max(mx_dif, x - y);

	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		dfs(nx, ny);
	}
}

void process() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (bio[i][j] || c[i][j] == '#') continue;

			mn_sum = mn_dif = 1e9;
			mx_sum = mx_dif = -1e9;
			ok = 1;
			cnt = 0;

			dfs(i, j);

			if (mx_sum - mn_sum == mx_dif - mn_dif && (mx_sum - mn_sum) % 2 == 0 && ok) {
				int d = (mx_sum - mn_sum) / 2 + 1;
				if (cnt == 2 * d * d - 2 * d + 1) sol++;
			}
		}
	}
	cout << sol;
	return;
}

signed main() {
	cin.tie(0)->sync_with_stdio(false);
	//freopen(".inp", "r", stdin);
	//freopen(".out", "w", stdout);
	process();
	cerr << "Time elapsed: " << __TIME << " s.\n";
	return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 277 ms 241236 KB Output is correct
15 Correct 36 ms 9524 KB Output is correct
16 Correct 106 ms 11348 KB Output is correct
17 Correct 190 ms 166484 KB Output is correct
18 Correct 49 ms 12156 KB Output is correct
19 Correct 100 ms 53440 KB Output is correct
20 Correct 116 ms 46656 KB Output is correct
21 Correct 86 ms 29268 KB Output is correct
22 Correct 95 ms 19008 KB Output is correct
23 Correct 84 ms 18000 KB Output is correct
24 Correct 99 ms 19268 KB Output is correct
25 Correct 212 ms 211664 KB Output is correct
26 Correct 56 ms 11144 KB Output is correct