Submission #161811

#TimeUsernameProblemLanguageResultExecution timeMemory
161811andrewRectangles (IOI19_rect)C++17
25 / 100
5095 ms77000 KiB
#include <bits/stdc++.h> #include "rect.h" #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> using namespace std; typedef long long ll; typedef long double ld; const ll MAXN = 1123456; const ll N = 2510, M = 90; int prv[N][N], nxt[N][N]; int prv1[N][N], nxt1[N][N]; deque <pii> q; int strU[M][M][M], strD[M][M][M], stlL[M][M][M], stlR[M][M][M]; long long count_rectangles(vector<vector<int> > a) { ll n = a.size(), m = a[0].size(); if(n < 3)return 0; if(n == 3){ int ans = 0, mx = 0; for(int i = 1; i < m - 1; i++){ mx = 0; for(int j = i; j < m - 1; j++){ mx = max(mx, a[1][j]); if(a[0][j] <= a[1][j] || a[2][j] <= a[1][j])break; if(a[1][i - 1] > mx && mx < a[1][j + 1])ans++; } } return ans; } for(int i = 0; i < n; i++){ vector <pii> st; st.push_back({1e8, -1}); for(int j = 0; j < m; j++){ while(!st.empty() && st.back().fi < a[i][j])st.pop_back(); prv[i][j] = st.back().se; st.push_back({a[i][j], j}); } st.clear(); st.push_back({1e8, m}); for(int j = m - 1; j >= 0; j--){ while(!st.empty() && st.back().fi < a[i][j])st.pop_back(); nxt[i][j] = st.back().se; st.push_back({a[i][j], j}); } st.clear(); } for(int j = 0; j < m; j++){ vector <pii> st; st.push_back({1e8, -1}); for(int i = 0; i < n; i++){ while(!st.empty() && st.back().fi < a[i][j])st.pop_back(); prv1[i][j] = st.back().se; st.push_back({a[i][j], i}); } st.clear(); st.push_back({1e8, n}); for(int i = n - 1; i >= 0; i--){ while(!st.empty() && st.back().fi < a[i][j])st.pop_back(); nxt1[i][j] = st.back().se; st.push_back({a[i][j], i}); } st.clear(); } // for(int i = 0; i < n; i++){ // for(int l = 0; l < m; l++){ // // } // } int ans = 0; for(int r1 = 1; r1 < n - 1; r1++) for(int c1 = 1; c1 < m - 1; c1++) for(int r2 = r1; r2 < n - 1; r2++) for(int c2 = c1; c2 < m - 1; c2++){ bool ok = 1; for(int i = c1; i <= c2; i++){ if(nxt1[r1 - 1][i] <= r2)ok = 0; } for(int i = c1; i <= c2; i++){ if(prv1[r2 + 1][i] >= r1)ok = 0; } for(int i = r1; i <= r2; i++){ if(nxt[i][c1 - 1] <= c2)ok = 0; } for(int i = r1; i <= r2; i++){ if(prv[i][c2 + 1] >= c1)ok = 0; } ans += ok; } return ans; }

Compilation message (stderr)

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:90:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int r1 = 1; r1 < n - 1; r1++)
     ^~~
rect.cpp:110:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  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...