Submission #960618

#TimeUsernameProblemLanguageResultExecution timeMemory
960618AkibAzmainRectangles (IOI19_rect)C++17
0 / 100
1 ms604 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; using ll = long long; long long count_rectangles (std::vector<std::vector<int> > a) { ll n = a.size (); ll m = a[0].size (); vector < vector < bool > > vis (n, vector < bool > (m)); int c = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++i) if (a[i][j] == 0) { int k = i, l = j; while (k + 1 < n && a[k + 1][j] == 0) ++k; while (l + 1 < m && a[i][l + 1] == 0) ++l; bool y = true; for (int ii = i + 1; y && ii <= k; ++ii) for (int jj = j + 1; y && jj <= l; ++jj) if (a[ii][jj]) y = false; for (int ii = i; y && ii <= k; ++ii) if (j - 1 < 0 || j + 1 >= m || a[ii][j - 1] == 0 || a[ii][j + 1] == 0) y = false; for (int ii = i; y && ii <= l; ++ii) if (i - 1 < 0 || i + 1 >= n || a[i - 1][ii] == 0 || a[i + 1][ii] == 0) y = false; if (y) ++c; queue < pair < int, int > > q; q.push ({ i, j }); while (q.size ()) { auto [x, y] = q.front (); q.pop (); if (x < 0 || x >= n || y < 0 || y >= m || a[x][y]) continue; a[x][y] = 1; q.push ({ x - 1, y }); q.push ({ x + 1, y }); q.push ({ x, y - 1 }); q.push ({ x, y + 1 }); } } return c; // vector < vector < vector < ll > > > // ra (n, vector < vector < ll > > (m, vector < ll > (m))), // ca (m, vector < vector < ll > > (n, vector < ll > (n))); // for (ll k = 0; k < n; ++k) // for (ll i = 0; i < m; ++i) // { // int mx = 0; // for (ll j = i + 2; j < m; ++j) // { // mx = max (mx, a[k][j - 1]); // if (mx < a[k][i] && mx < a[k][j]) ra[k][i + 1][j - 1] = 1; // } // } // for (ll k = 0; k < m; ++k) // for (ll i = 0; i < n; ++i) // { // int mx = 0; // for (ll j = i + 2; j < n; ++j) // { // mx = max (mx, a[j - 1][k]); // if (mx < a[i][k] && mx < a[j][k]) ca[k][i + 1][j - 1] = 1; // } // } // for (ll i = 1; i < n; ++i) // for (ll j = 0; j < m; ++j) // for (ll k = 0; k < m; ++k) // ra[i][j][k] += ra[i - 1][j][k]; // for (ll i = 1; i < m; ++i) // for (ll j = 0; j < n; ++j) // for (ll k = 0; k < n; ++k) // ca[i][j][k] += ca[i - 1][j][k]; // auto alp = [&] (auto &x, int a, int b, int c, int d) // { // return (x[d][a][b] - (c ? x[c - 1][a][b] : 0)) == d - c + 1; // }; // int c = 0; // for (ll i1 = 0; i1 < n; ++i1) // for (ll i2 = i1; i2 < n; ++i2) // for (ll j1 = 0; j1 < m; ++j1) // for (ll j2 = j1; j2 < m; ++j2) // if (alp (ca, i1, i2, j1, j2) && alp (ra, j1, j2, i1, i2)) // ++c; // return c; }
#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...