#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
using lll = long long;
const ll maxn = 2500;
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;
ll sub6 = 1;
for(auto &o : a) for(ll &i : o) if (i>1) sub6 = 0;
if (0&&sub6){
//cerr << "sub6\n";
ll ans = 0;
//cerr << "sub6\n";
for(ll w = 1;w<n-1;w++){
for(ll i = 1;i<n-w;i++){
ll c = 0;
for(ll j = 1;j<m-1;j++){
if(a[i][j])ans+=c*(c+1),c=0;
else c++;
a[i][j] |= a[i+1][j];
}
ans+=c*(c+1);
}
//cerr << ans << "\n";
}
return ans/2;
}
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]){
if(j>st.back().second+1)row[i].push_back({st.back().second,j});
st.pop_back();
}
if(st.size()){
if(j>st.back().second+1)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]){
if(i>st.back().second+1)col[j].push_back({st.back().second,i});
st.pop_back();
}
if(st.size()){
if(i>st.back().second+1)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());
lll ans = 0;
for(ll r1 = 1;r1<n-1;r1++){
vector<pair<ll,ll>> cur = row[r1];
vector<pair<ll,ll>> nw;
for(ll r2 = r1;r2<n-1;r2++){
if(r2>r1){
for(auto &o : cur){
if (binary_search(row[r2].begin(),row[r2].end(),o)){
nw.push_back(o);
}
}
nw.swap(cur);
nw.clear();
}
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)) ans++;
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
10 ms |
604 KB |
Output is correct |
23 |
Correct |
6 ms |
604 KB |
Output is correct |
24 |
Correct |
10 ms |
692 KB |
Output is correct |
25 |
Correct |
6 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
672 KB |
Output is correct |
27 |
Correct |
6 ms |
600 KB |
Output is correct |
28 |
Correct |
7 ms |
604 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
6 ms |
604 KB |
Output is correct |
19 |
Correct |
10 ms |
692 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
672 KB |
Output is correct |
22 |
Correct |
6 ms |
600 KB |
Output is correct |
23 |
Correct |
7 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
90 ms |
1780 KB |
Output is correct |
31 |
Correct |
103 ms |
1784 KB |
Output is correct |
32 |
Correct |
92 ms |
1860 KB |
Output is correct |
33 |
Correct |
42 ms |
1116 KB |
Output is correct |
34 |
Correct |
51 ms |
1628 KB |
Output is correct |
35 |
Correct |
53 ms |
1860 KB |
Output is correct |
36 |
Correct |
89 ms |
1808 KB |
Output is correct |
37 |
Correct |
58 ms |
1972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
6 ms |
604 KB |
Output is correct |
19 |
Correct |
10 ms |
692 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
672 KB |
Output is correct |
22 |
Correct |
6 ms |
600 KB |
Output is correct |
23 |
Correct |
7 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
90 ms |
1780 KB |
Output is correct |
26 |
Correct |
103 ms |
1784 KB |
Output is correct |
27 |
Correct |
92 ms |
1860 KB |
Output is correct |
28 |
Correct |
42 ms |
1116 KB |
Output is correct |
29 |
Correct |
51 ms |
1628 KB |
Output is correct |
30 |
Correct |
53 ms |
1860 KB |
Output is correct |
31 |
Correct |
89 ms |
1808 KB |
Output is correct |
32 |
Correct |
58 ms |
1972 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
2270 ms |
12988 KB |
Output is correct |
39 |
Correct |
2098 ms |
12848 KB |
Output is correct |
40 |
Correct |
2220 ms |
12968 KB |
Output is correct |
41 |
Correct |
2252 ms |
12968 KB |
Output is correct |
42 |
Correct |
4948 ms |
18564 KB |
Output is correct |
43 |
Correct |
4568 ms |
18516 KB |
Output is correct |
44 |
Correct |
4736 ms |
18876 KB |
Output is correct |
45 |
Correct |
4165 ms |
18192 KB |
Output is correct |
46 |
Correct |
1968 ms |
8124 KB |
Output is correct |
47 |
Correct |
2193 ms |
10828 KB |
Output is correct |
48 |
Correct |
2635 ms |
17220 KB |
Output is correct |
49 |
Correct |
2514 ms |
18776 KB |
Output is correct |
50 |
Correct |
1137 ms |
9624 KB |
Output is correct |
51 |
Correct |
603 ms |
9764 KB |
Output is correct |
52 |
Correct |
2725 ms |
18108 KB |
Output is correct |
53 |
Correct |
2659 ms |
18708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
688 KB |
Output is correct |
7 |
Correct |
1 ms |
528 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Execution timed out |
5069 ms |
46944 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
6 ms |
604 KB |
Output is correct |
19 |
Correct |
10 ms |
692 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
672 KB |
Output is correct |
22 |
Correct |
6 ms |
600 KB |
Output is correct |
23 |
Correct |
7 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
90 ms |
1780 KB |
Output is correct |
26 |
Correct |
103 ms |
1784 KB |
Output is correct |
27 |
Correct |
92 ms |
1860 KB |
Output is correct |
28 |
Correct |
42 ms |
1116 KB |
Output is correct |
29 |
Correct |
51 ms |
1628 KB |
Output is correct |
30 |
Correct |
53 ms |
1860 KB |
Output is correct |
31 |
Correct |
89 ms |
1808 KB |
Output is correct |
32 |
Correct |
58 ms |
1972 KB |
Output is correct |
33 |
Correct |
2270 ms |
12988 KB |
Output is correct |
34 |
Correct |
2098 ms |
12848 KB |
Output is correct |
35 |
Correct |
2220 ms |
12968 KB |
Output is correct |
36 |
Correct |
2252 ms |
12968 KB |
Output is correct |
37 |
Correct |
4948 ms |
18564 KB |
Output is correct |
38 |
Correct |
4568 ms |
18516 KB |
Output is correct |
39 |
Correct |
4736 ms |
18876 KB |
Output is correct |
40 |
Correct |
4165 ms |
18192 KB |
Output is correct |
41 |
Correct |
1968 ms |
8124 KB |
Output is correct |
42 |
Correct |
2193 ms |
10828 KB |
Output is correct |
43 |
Correct |
2635 ms |
17220 KB |
Output is correct |
44 |
Correct |
2514 ms |
18776 KB |
Output is correct |
45 |
Correct |
1137 ms |
9624 KB |
Output is correct |
46 |
Correct |
603 ms |
9764 KB |
Output is correct |
47 |
Correct |
2725 ms |
18108 KB |
Output is correct |
48 |
Correct |
2659 ms |
18708 KB |
Output is correct |
49 |
Correct |
2 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
2 ms |
688 KB |
Output is correct |
55 |
Correct |
1 ms |
528 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
0 ms |
444 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
344 KB |
Output is correct |
61 |
Execution timed out |
5069 ms |
46944 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |