#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int xx[]={0, 1, 0, -1}, yy[]={1, 0, -1, 0};
struct dat{
int x, y, v;
dat(){}
dat(int x, int y, int v): x(x), y(y), v(v){}
bool operator<(const dat &r)const{
return v<r.v;
}
};
int n, m;
int arr[1502][1502];
ll ans;
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
scanf("%d", &arr[i][j]);
// arr[i][j] = i*m + (i%2 ? j : m-j+1);
}
}
int minV, x, y, minD, cnt;
for(int a=1; a<=n; a++){
for(int b=a; b<=n; b++){
for(int c=1; c<=m; c++){
for(int d=c; d<=m; d++){
minV = 2e9, x = 0, y = 0, cnt = 1;
for(int i=a; i<=b; i++) for(int j=c; j<=d; j++){
if(minV > arr[i][j]) minV = arr[i][j], x = i, y = j;
}
while(1){
minV = 2e9, minD = -1;
for(int dir=0; dir<4; dir++){
int tx = x+xx[dir], ty = y+yy[dir];
if(tx<a || tx>b || ty<c || ty>d || arr[x][y] > arr[tx][ty]) continue;
if(minV > arr[tx][ty]) minV = arr[tx][ty], minD = dir;
}
if(minD == -1) break;
cnt++;
x += xx[minD], y += yy[minD];
}
if(cnt == (b-a+1)*(d-c+1)) ans++;
}
}
}
}
printf("%lld", ans);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d", &arr[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5060 ms |
468 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Execution timed out |
5078 ms |
6228 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Execution timed out |
5078 ms |
6228 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Execution timed out |
5078 ms |
6228 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |