#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
13 ms |
1116 KB |
Output is correct |
23 |
Correct |
12 ms |
1116 KB |
Output is correct |
24 |
Correct |
12 ms |
1144 KB |
Output is correct |
25 |
Correct |
9 ms |
604 KB |
Output is correct |
26 |
Correct |
12 ms |
1136 KB |
Output is correct |
27 |
Correct |
11 ms |
1112 KB |
Output is correct |
28 |
Correct |
11 ms |
1128 KB |
Output is correct |
29 |
Correct |
5 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
13 ms |
1116 KB |
Output is correct |
18 |
Correct |
12 ms |
1116 KB |
Output is correct |
19 |
Correct |
12 ms |
1144 KB |
Output is correct |
20 |
Correct |
9 ms |
604 KB |
Output is correct |
21 |
Correct |
12 ms |
1136 KB |
Output is correct |
22 |
Correct |
11 ms |
1112 KB |
Output is correct |
23 |
Correct |
11 ms |
1128 KB |
Output is correct |
24 |
Correct |
5 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
201 ms |
3976 KB |
Output is correct |
31 |
Correct |
183 ms |
3932 KB |
Output is correct |
32 |
Correct |
185 ms |
3932 KB |
Output is correct |
33 |
Correct |
153 ms |
3928 KB |
Output is correct |
34 |
Correct |
192 ms |
3928 KB |
Output is correct |
35 |
Correct |
192 ms |
3928 KB |
Output is correct |
36 |
Correct |
199 ms |
3928 KB |
Output is correct |
37 |
Correct |
195 ms |
3956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
13 ms |
1116 KB |
Output is correct |
18 |
Correct |
12 ms |
1116 KB |
Output is correct |
19 |
Correct |
12 ms |
1144 KB |
Output is correct |
20 |
Correct |
9 ms |
604 KB |
Output is correct |
21 |
Correct |
12 ms |
1136 KB |
Output is correct |
22 |
Correct |
11 ms |
1112 KB |
Output is correct |
23 |
Correct |
11 ms |
1128 KB |
Output is correct |
24 |
Correct |
5 ms |
604 KB |
Output is correct |
25 |
Correct |
201 ms |
3976 KB |
Output is correct |
26 |
Correct |
183 ms |
3932 KB |
Output is correct |
27 |
Correct |
185 ms |
3932 KB |
Output is correct |
28 |
Correct |
153 ms |
3928 KB |
Output is correct |
29 |
Correct |
192 ms |
3928 KB |
Output is correct |
30 |
Correct |
192 ms |
3928 KB |
Output is correct |
31 |
Correct |
199 ms |
3928 KB |
Output is correct |
32 |
Correct |
195 ms |
3956 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Execution timed out |
5036 ms |
31968 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1096 KB |
Output is correct |
2 |
Correct |
2 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
956 KB |
Output is correct |
6 |
Correct |
2 ms |
1076 KB |
Output is correct |
7 |
Correct |
2 ms |
1000 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
5093 ms |
149512 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
13 ms |
1116 KB |
Output is correct |
18 |
Correct |
12 ms |
1116 KB |
Output is correct |
19 |
Correct |
12 ms |
1144 KB |
Output is correct |
20 |
Correct |
9 ms |
604 KB |
Output is correct |
21 |
Correct |
12 ms |
1136 KB |
Output is correct |
22 |
Correct |
11 ms |
1112 KB |
Output is correct |
23 |
Correct |
11 ms |
1128 KB |
Output is correct |
24 |
Correct |
5 ms |
604 KB |
Output is correct |
25 |
Correct |
201 ms |
3976 KB |
Output is correct |
26 |
Correct |
183 ms |
3932 KB |
Output is correct |
27 |
Correct |
185 ms |
3932 KB |
Output is correct |
28 |
Correct |
153 ms |
3928 KB |
Output is correct |
29 |
Correct |
192 ms |
3928 KB |
Output is correct |
30 |
Correct |
192 ms |
3928 KB |
Output is correct |
31 |
Correct |
199 ms |
3928 KB |
Output is correct |
32 |
Correct |
195 ms |
3956 KB |
Output is correct |
33 |
Execution timed out |
5036 ms |
31968 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |