Submission #1067938

#TimeUsernameProblemLanguageResultExecution timeMemory
1067938LittleOrangeRectangles (IOI19_rect)C++17
37 / 100
5093 ms149512 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(), m = a[0].size(); if (n<3||m<3) return 0; vector<vector<pair<ll,ll>>> row(n),col(m); for(ll i = 0;i<n;i++){ vector<pair<ll,ll>> st; for(ll j = 0;j<m;j++){ while(st.size()&&st.back().first<a[i][j]){ row[i].push_back({st.back().second,j}); st.pop_back(); } if(st.size()){ row[i].push_back({st.back().second,j}); } if (st.size()&&st.back().first==a[i][j]) st.pop_back(); st.push_back({a[i][j],j}); } } for(ll j = 0;j<m;j++){ vector<pair<ll,ll>> st; for(ll i = 0;i<n;i++){ while(st.size()&&st.back().first<a[i][j]){ col[j].push_back({st.back().second,i}); st.pop_back(); } if(st.size()){ col[j].push_back({st.back().second,i}); } if (st.size()&&st.back().first==a[i][j]) st.pop_back(); st.push_back({a[i][j],i}); } } for(auto &o : row) sort(o.begin(),o.end()); for(auto &o : col) sort(o.begin(),o.end()); ll ans = 0; for(ll r1 = 1;r1<n-1;r1++){ vector<pair<ll,ll>> cur = row[r1]; for(ll r2 = r1;r2<n-1;r2++){ if(r2>r1){ vector<pair<ll,ll>> nw; for(auto &o : cur){ if (binary_search(row[r2].begin(),row[r2].end(),o)){ nw.push_back(o); } } nw.swap(cur); } pair<ll,ll> t = {r1-1,r2+1}; vector<ll> ok(m,0); for(ll i = 0;i<m;i++) ok[i] = binary_search(col[i].begin(),col[i].end(),t); vector<ll> p(m+1,0); for(ll i = 0;i<m;i++) p[i+1] = p[i]+ok[i]; for(auto &o : cur){ if (p[o.second]-p[o.first+1]==(o.second-o.first-1)&&o.second-o.first>1) 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...