Submission #143714

#TimeUsernameProblemLanguageResultExecution timeMemory
143714qkxwsmRectangles (IOI19_rect)C++14
13 / 100
525 ms147912 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define y1 qkx #define y2 wsm #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define MAXN 2513 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; int N, M; vector<vi> grid; int rt[MAXN][MAXN], dn[MAXN][MAXN]; int pref[MAXN][MAXN]; ll ans; int psum(int x1, int x2, int y1, int y2) { return pref[x2 + 1][y2 + 1] - pref[x1][y2 + 1] - pref[x2 + 1][y1] + pref[x1][y1]; } ll count_rectangles(vector<vi> a) { N = SZ(a); M = SZ(a[0]); grid = a; int mx = 0; FOR(i, 0, N) FOR(j, 0, M) ckmax(mx, grid[i][j]); if (mx <= 1) { FOR(i, 0, N) { FOR(j, 0, M) { pref[i + 1][j + 1] = pref[i][j + 1] + pref[i + 1][j] - pref[i][j] + grid[i][j]; } } //for each square, compute the next 1 on the right FOR(i, 0, N) { rt[i][M] = M; FORD(j, M, 0) { rt[i][j] = (grid[i][j] ? j : rt[i][j + 1]); } } FOR(i, 0, M) { dn[N][i] = N; FORD(j, N, 0) { dn[j][i] = (grid[j][i] ? j : dn[j + 1][i]); } } FOR(x1, 1, N) { FOR(y1, 1, M) { if (grid[x1][y1]) continue; int y2 = rt[x1][y1] - 1, x2 = dn[x1][y1] - 1; if (x2 == N - 1 || y2 == M - 1) continue; // cerr << "CONSIDER " << x1 << ' ' << y1 << " -> " << x2 << ' ' << y2 << endl; if (psum(x1, x2, y1, y2) != 0) continue; if (psum(x1 - 1, x1 - 1, y1, y2) != (y2 - y1 + 1)) continue; if (psum(x2 + 1, x2 + 1, y1, y2) != (y2 - y1 + 1)) continue; if (psum(x1, x2, y1 - 1, y1 - 1) != (x2 - x1 + 1)) continue; if (psum(x1, x2, y2 + 1, y2 + 1) != (x2 - x1 + 1)) continue; ans++; } } } return ans; }
#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...