Submission #810258

#TimeUsernameProblemLanguageResultExecution timeMemory
810258Sohsoh84Rectangles (IOI19_rect)C++17
59 / 100
5100 ms820020 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define X first #define Y second #define all(x) (x).begin(), (x).end() #define sep ' ' #define debug(x) cerr << #x << ": " << x << endl; const int MAXN = 2500 + 10; int n, m, A[MAXN][MAXN], L[MAXN], R[MAXN]; map<pll, int> mp_r[MAXN], mp_c[MAXN]; vector<int> F[MAXN][MAXN]; vector<pair<pll, pll>> ans_vec; inline void add(int l1, int l2, int r1, int r2) { if (l2 - l1 <= 1 || r2 - r1 <= 1) return; ans_vec.push_back({{l1, l2}, {r1, r2}}); } ll count_rectangles(vector<vector<int>> vec_) { n = vec_.size(); m = vec_[0].size(); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) A[i][j] = vec_[i - 1][j - 1]; for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) for (L[i] = i - 1; L[i] > 0 && A[L[i]][j] < A[i][j]; L[i] = L[L[i]]); for (int i = n; i > 0; i--) for (R[i] = i + 1; R[i] <= n && A[R[i]][j] < A[i][j]; R[i] = R[R[i]]); for (int i = 1; i <= n; i++) { if (L[i]) { mp_c[j][pll(L[i], i)] = mp_c[j - 1][pll(L[i], i)] + 1; F[i][j].push_back(L[i]); } if (R[i] <= n) { mp_c[j][pll(i, R[i])] = mp_c[j - 1][pll(i, R[i])] + 1; F[R[i]][j].push_back(i); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) for (L[j] = j - 1; L[j] > 0 && A[i][L[j]] < A[i][j]; L[j] = L[L[j]]); for (int j = m; j > 0; j--) for (R[j] = j + 1; R[j] <= m && A[i][R[j]] < A[i][j]; R[j] = R[R[j]]); for (int j = 1; j <= m; j++) { if (L[j]) mp_r[i][pll(L[j], j)] = mp_r[i - 1][pll(L[j], j)] + 1; if (R[j] <= m) mp_r[i][pll(j, R[j])] = mp_r[i - 1][pll(j, R[j])] + 1; } if (i == n) continue; for (int j = 1; j <= m; j++) { if (L[j]) { for (int f : F[i + 1][j - 1]) { if (mp_r[i][pll(L[j], j)] >= i - f && mp_c[j - 1][pll(f, i + 1)] >= j - L[j] - 1) add(f, i + 1, L[j], j); } } if (R[j] <= m) { for (int f : F[i + 1][j + 1]) { if (mp_r[i][pll(j, R[j])] >= i - f && mp_c[R[j] - 1][pll(f, i + 1)] >= R[j] - j - 1) add(f, i + 1, j, R[j]); } } } } sort(all(ans_vec)); ans_vec.resize(unique(all(ans_vec)) - ans_vec.begin()); return ans_vec.size(); }
#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...