Submission #1032388

#TimeUsernameProblemLanguageResultExecution timeMemory
1032388shmaxRectangles (IOI19_rect)C++17
10 / 100
3044 ms1048576 KiB
#include "rect.h" #include <bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("avx,avx2,bmi,bmi2") using namespace std; using i32 = int; //#define int long long #define len(x) (int)(x.size()) #define inf 1000'000'000'000'000'000LL #define all(x) x.begin(), x.end() #define low_bit(x) (x & (-x)) template<typename T> using vec = vector<T>; const int maxM = 701; long long count_rectangles(std::vector<std::vector<i32>> a) { int n = len(a); int m = len(a[0]); long long ans = 0; vec<vec<bitset<maxM>>> b(n, vec<bitset<maxM>>(m)); for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m - 1; j++) { b[i][j].reset(); int mx = a[i][j]; for (int l = i; l < n - 1; l++) { mx = max(mx, a[l][j]); if (mx >= min(a[i - 1][j], a[l + 1][j])) continue; b[i][j][l] = true; } } } vec<vec<bitset<maxM>>> good(m, vec<bitset<maxM>>(m)); vec<vec<vec<int>>> maxVal(n, vec<vec<int>>(m, vec<int>(m, 0))); for (int i = 1; i < n - 1; i++) { for (int l = 1; l < m - 1; l++) { for (int r = l; r < m - 1; r++) { maxVal[i][l][r] = max(maxVal[i][l][r - 1], a[i][r]); } } } for (int l = 1; l < m - 1; l++) { for (int r = l; r < m - 1; r++) { for (int i = 0; i < n; i++) { good[l][r][i] = maxVal[i][l][r] < min(a[i][l - 1], a[i][r + 1]); } } } for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m - 1; j++) { if (a[i][j] >= a[i - 1][j]) continue; if (a[i][j] >= a[i][j - 1]) continue; bitset<maxM> cur = b[i][j]; for (int k = j; k < m - 1; k++) { cur &= b[i][k]; ans += (cur & good[j][k]).count(); } } } 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...