#include<bits/stdc++.h>
#include <cstdio>
#include <unistd.h>
#include <cassert>
#include <string>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
const int nax=2505;
int segtree[nax*4];
vector<vector<int>> grid;
void build(int pos,int l,int r){
if(l==r){
segtree[pos]=grid[1][l];
return;
}
int mid=(r+l)/2;
build(pos*2+1,l,mid);
build(pos*2+2,mid+1,r);
segtree[pos]=max(segtree[pos*2+1],segtree[pos*2+2]);
}
int query(int pos,int l,int r,int left,int right){
if(l>r||l>right||r<left) return -1e9;
if(l>=left&&r<=right) return segtree[pos];
int mid=(r+l)/2;
return max(query(pos*2+1,l,mid,left,right),query(pos*2+2,mid+1,r,left,right));
}
long long count_rectangles(std::vector<std::vector<int> > a) {
grid=a;
int n=a.size();
if(n<=2){
return 0;
}
int m=a[0].size();
if(m<=2) return 0;
int ans=0;
for (int i = 1; i < n-1; ++i)
{
for (int j = 1; j < m-1; ++j)
{
for (int k = i; k < n-1; ++k)
{
for (int t = j; t < m-1; ++t)
{
bool test=true;
for (int x = i; x <= k; ++x)
{
for (int y = j; y <= t; ++y)
{
if(grid[x][y]>=grid[x][j-1]) test=false;
else if(grid[x][y]>=grid[x][t+1]) test=false;
else if(grid[x][y]>=grid[i-1][y]) test=false;
else if(grid[x][y]>=grid[k+1][y]) test=false;
if(!test) break;
}
if(!test) break;
}
ans+=test;
}
}
}
}
return ans;
}
class InputReader {
private:
static const int SIZE = 4096;
int inputFileDescriptor;
char buf[SIZE];
int curChar;
int numChars;
public:
inline InputReader(int _inputFileDescriptor):
inputFileDescriptor(_inputFileDescriptor),
curChar(0),
numChars(0) {
}
inline void close() {
::close(inputFileDescriptor);
}
inline char read() {
assert(numChars != -1);
if (curChar >= numChars) {
curChar = 0;
numChars = ::read(inputFileDescriptor, buf, SIZE);
if (numChars == -1)
return -1;
}
return buf[curChar++];
}
inline int readInt() {
int c = eatWhite();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
assert(c >= '0' && c <= '9');
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
inline string readString() {
char c = eatWhite();
string res;
do {
res += c;
c = read();
} while (!isSpaceChar(c));
return res;
}
inline string readLine() {
string res;
while (true) {
char c = read();
if (c == '\n' || c == '\r' || c == -1)
break;
res += c;
}
return res;
}
inline char eatWhite() {
char c = read();
while (isSpaceChar(c))
c = read();
return c;
}
static inline bool isSpaceChar(char c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
};
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
424 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
424 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
30 ms |
600 KB |
Output is correct |
23 |
Correct |
30 ms |
344 KB |
Output is correct |
24 |
Correct |
30 ms |
348 KB |
Output is correct |
25 |
Correct |
18 ms |
344 KB |
Output is correct |
26 |
Correct |
21 ms |
532 KB |
Output is correct |
27 |
Correct |
21 ms |
348 KB |
Output is correct |
28 |
Correct |
26 ms |
348 KB |
Output is correct |
29 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
424 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
30 ms |
600 KB |
Output is correct |
18 |
Correct |
30 ms |
344 KB |
Output is correct |
19 |
Correct |
30 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
344 KB |
Output is correct |
21 |
Correct |
21 ms |
532 KB |
Output is correct |
22 |
Correct |
21 ms |
348 KB |
Output is correct |
23 |
Correct |
26 ms |
348 KB |
Output is correct |
24 |
Correct |
6 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1204 ms |
1116 KB |
Output is correct |
31 |
Correct |
1194 ms |
1112 KB |
Output is correct |
32 |
Correct |
1241 ms |
1204 KB |
Output is correct |
33 |
Correct |
715 ms |
984 KB |
Output is correct |
34 |
Correct |
812 ms |
860 KB |
Output is correct |
35 |
Correct |
826 ms |
1116 KB |
Output is correct |
36 |
Correct |
855 ms |
1116 KB |
Output is correct |
37 |
Correct |
791 ms |
1192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
424 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
30 ms |
600 KB |
Output is correct |
18 |
Correct |
30 ms |
344 KB |
Output is correct |
19 |
Correct |
30 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
344 KB |
Output is correct |
21 |
Correct |
21 ms |
532 KB |
Output is correct |
22 |
Correct |
21 ms |
348 KB |
Output is correct |
23 |
Correct |
26 ms |
348 KB |
Output is correct |
24 |
Correct |
6 ms |
348 KB |
Output is correct |
25 |
Correct |
1204 ms |
1116 KB |
Output is correct |
26 |
Correct |
1194 ms |
1112 KB |
Output is correct |
27 |
Correct |
1241 ms |
1204 KB |
Output is correct |
28 |
Correct |
715 ms |
984 KB |
Output is correct |
29 |
Correct |
812 ms |
860 KB |
Output is correct |
30 |
Correct |
826 ms |
1116 KB |
Output is correct |
31 |
Correct |
855 ms |
1116 KB |
Output is correct |
32 |
Correct |
791 ms |
1192 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Execution timed out |
5038 ms |
9300 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
14 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
344 KB |
Output is correct |
7 |
Correct |
11 ms |
348 KB |
Output is correct |
8 |
Correct |
10 ms |
528 KB |
Output is correct |
9 |
Correct |
10 ms |
532 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
7 |
Execution timed out |
5046 ms |
34140 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
436 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
424 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
30 ms |
600 KB |
Output is correct |
18 |
Correct |
30 ms |
344 KB |
Output is correct |
19 |
Correct |
30 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
344 KB |
Output is correct |
21 |
Correct |
21 ms |
532 KB |
Output is correct |
22 |
Correct |
21 ms |
348 KB |
Output is correct |
23 |
Correct |
26 ms |
348 KB |
Output is correct |
24 |
Correct |
6 ms |
348 KB |
Output is correct |
25 |
Correct |
1204 ms |
1116 KB |
Output is correct |
26 |
Correct |
1194 ms |
1112 KB |
Output is correct |
27 |
Correct |
1241 ms |
1204 KB |
Output is correct |
28 |
Correct |
715 ms |
984 KB |
Output is correct |
29 |
Correct |
812 ms |
860 KB |
Output is correct |
30 |
Correct |
826 ms |
1116 KB |
Output is correct |
31 |
Correct |
855 ms |
1116 KB |
Output is correct |
32 |
Correct |
791 ms |
1192 KB |
Output is correct |
33 |
Execution timed out |
5038 ms |
9300 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |