This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,m;
int arr[1500][1500];
vector<ii> idx;
int dist(ii i,ii j){
return abs(i.fi-j.fi)+abs(i.se-j.se);
}
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>m;
rep(x,0,n) rep(y,0,m){
cin>>arr[x][y];
idx.pub({x,y});
}
sort(all(idx),[](ii i,ii j){
return arr[i.fi][i.se]<arr[j.fi][j.se];
});
int ans=0;
rep(x1,0,n) rep(x2,x1,n) rep(y1,0,m) rep(y2,y1,m){
ii p={-1,-1};
bool ok=true;
for (auto it:idx) if (x1<=it.fi && it.fi<=x2 && y1<=it.se && it.se<=y2){
if (p!=ii(-1,-1) && dist(it,p)>1){
ok=false;
break;
}
p=it;
}
if (ok) 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... |