이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[50013];
int h, w;
int id(int i, int j){
return i * w + j;
}
int32_t main(){
cin >> h >> w;
for(int i = 0; i < h * w; i++){
cin >> a[i];
}
{
set<int> S; map<int, int> M;
for(int i = 0; i < h * w; i++){
S.insert(a[i]);
}
int idx = 0;
for(auto j : S){
M[j] = idx++;
}
for(int i = 0; i < h * w; i++){
a[i] = M[a[i]];
}
}
int ans = 0;
for(int u = 0; u < h; u++){
for(int b = u; b < h; b++){
for(int l = 0; l < w; l++){
for(int r = l; r < w; r++){
int x = u, y = l; int cnt = 1;
for(int i = u; i <= b; i++){
for(int j = l; j <= r; j++){
if(a[id(i, j)] > a[id(x, y)])
x = i, y = j;
}
}
while(cnt != (u - b + 1) * (r - l + 1)){
int nx = -1, ny = -1;
for(auto dir : vector<pair<int, int>> {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}){
int rx = x + dir.first, ry = y + dir.second;
if(rx > b || rx < u || ry > r || ry < l || a[id(rx, ry)] > a[id(x, y)]) continue;
if(nx == -1 || a[id(nx, ny)] < a[id(rx, ry)]) nx = rx, ny = ry;
}
if(nx == -1) break;
x = nx, y = ny;
cnt++;
}
if(cnt == (b - u + 1) * (r - l + 1)){
ans++;
}
}
}
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |