#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;
}
bool good(const dat &r)const{
return abs(x-r.x)+abs(y-r.y)==1;
}
};
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);
}
}
if(n>m){
swap(n, m);
for(int i=1; i<=max(n, m); i++) for(int j=i+1; j<=max(n, m); j++) swap(arr[i][j], arr[j][i]);
}
// int minV, x, y, minD, cnt;
for(int a=1; a<=n; a++){
for(int b=a; b<=n; b++){ /// ���� a �̻� b ����
for(int c=1; c<=m; c++){ /// c������ ����
set<dat> st;
int cnt = 0;
for(int d=c; d<=m; d++){
for(int i=a; i<=b; i++){
auto it = st.insert(dat(i, d, arr[i][d])).first;
if(next(it) != st.end() && !next(it)->good(*it)) cnt++;
if(it != st.begin() && !prev(it)->good(*it)) cnt++;
if(next(it) != st.end() && it != st.begin() && !prev(it)->good(*next(it))) cnt--;
}
if(!cnt) ans++;
}
}
}
}
printf("%lld", ans);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:29:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d", &arr[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5072 ms |
3540 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
126 ms |
9172 KB |
Output is correct |
8 |
Correct |
145 ms |
9212 KB |
Output is correct |
9 |
Correct |
776 ms |
664 KB |
Output is correct |
10 |
Correct |
597 ms |
596 KB |
Output is correct |
11 |
Correct |
113 ms |
372 KB |
Output is correct |
12 |
Correct |
122 ms |
4804 KB |
Output is correct |
13 |
Correct |
805 ms |
548 KB |
Output is correct |
14 |
Correct |
340 ms |
496 KB |
Output is correct |
15 |
Correct |
684 ms |
604 KB |
Output is correct |
16 |
Correct |
717 ms |
580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
126 ms |
9172 KB |
Output is correct |
8 |
Correct |
145 ms |
9212 KB |
Output is correct |
9 |
Correct |
776 ms |
664 KB |
Output is correct |
10 |
Correct |
597 ms |
596 KB |
Output is correct |
11 |
Correct |
113 ms |
372 KB |
Output is correct |
12 |
Correct |
122 ms |
4804 KB |
Output is correct |
13 |
Correct |
805 ms |
548 KB |
Output is correct |
14 |
Correct |
340 ms |
496 KB |
Output is correct |
15 |
Correct |
684 ms |
604 KB |
Output is correct |
16 |
Correct |
717 ms |
580 KB |
Output is correct |
17 |
Runtime error |
12 ms |
12668 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
126 ms |
9172 KB |
Output is correct |
8 |
Correct |
145 ms |
9212 KB |
Output is correct |
9 |
Correct |
776 ms |
664 KB |
Output is correct |
10 |
Correct |
597 ms |
596 KB |
Output is correct |
11 |
Correct |
113 ms |
372 KB |
Output is correct |
12 |
Correct |
122 ms |
4804 KB |
Output is correct |
13 |
Correct |
805 ms |
548 KB |
Output is correct |
14 |
Correct |
340 ms |
496 KB |
Output is correct |
15 |
Correct |
684 ms |
604 KB |
Output is correct |
16 |
Correct |
717 ms |
580 KB |
Output is correct |
17 |
Runtime error |
12 ms |
12668 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |