Submission #1047669

# Submission time Handle Problem Language Result Execution time Memory
1047669 2024-08-07T14:52:49 Z MercubytheFirst Rectangles (IOI19_rect) C++14
13 / 100
350 ms 403540 KB
#include <bits/stdc++.h>
#include "rect.h"
using namespace std;
using ll = long long;

ll n, m;

long long count_rectangles(std::vector<std::vector<signed> > a) {
	n = a.size();
	m = a[0].size();
	vector<vector<bool> > vis(n, vector<bool>(m));
	auto ok = [&](ll x, ll y) -> bool
	{
		return 0 <= x and x < n and 0 <= y and y < m;
	};
	const ll dx[] = {0, +1, 0, -1},
						dy[] = {+1, 0, -1, 0};
	ll x = n + 1, y = m + 1, xx = -1, yy = -1, sz = 0;
	auto comp_dfs = [&] (auto&& dfs, ll i, ll j) -> void
	{
		assert(ok(i, j) and !vis[i][j] and a[i][j] == 0);
		++sz;
		vis[i][j] = true;
		x = min(x, i);
		xx = max(xx, i);
		y = min(y, j);
		yy = max(yy, j);
		for(ll d = 0; d < 4; ++d) {
			ll ii = i + dx[d], jj = j + dy[d];
			if(!ok(ii, jj) or vis[ii][jj] or a[ii][jj] == 1) {
				continue;
			}
			dfs(dfs, ii, jj);
		}
	};
	
	ll ans = 0;
	for(ll i = 0; i < n; ++i) {
		for(ll j = 0; j < m; ++j) {
			if(vis[i][j] or a[i][j] == 1) {
				continue;
			}
			x = n + 1, y = m + 1, xx = -1, yy = -1, sz = 0;
			comp_dfs(comp_dfs, i, j);
			if(x > xx or y > yy or x <= 0 or n - 1 <= xx or y <= 0 or m - 1 <= yy) {
				continue;
			}
			const ll ar = (xx - x + 1) * (yy - y + 1);
			if(ar == sz) {
				ans++;
			}
		}
	}
	return ans;
}

/*
5 5
1 1 1 1 1
1 0 0 0 1
1 1 1 1 1
1 0 1 0 1
1 1 1 1 1
*/
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 80 ms 23332 KB Output is correct
3 Correct 185 ms 53120 KB Output is correct
4 Correct 177 ms 56844 KB Output is correct
5 Correct 174 ms 53412 KB Output is correct
6 Correct 158 ms 139340 KB Output is correct
7 Correct 305 ms 337772 KB Output is correct
8 Correct 350 ms 403540 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -