Submission #1047669

#TimeUsernameProblemLanguageResultExecution timeMemory
1047669MercubytheFirstRectangles (IOI19_rect)C++14
13 / 100
350 ms403540 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...