# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886540 | dubabuba | Sandcastle 2 (JOI22_ho_t5) | C++14 | 5075 ms | 31324 KiB |
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 <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
const int mxn = 5050;
int a[mxn][mxn], n, m;
pii pos[mxn];
void build() {
map<int, int> mp;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
mp[a[i][j]];
int s = 0;
for(auto &p : mp)
p.second = s++;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++) {
a[i][j] = mp[a[i][j]];
pos[a[i][j]] = {i, j};
}
}
bool neighbour(int x, int y) {
const pii &px = pos[x];
const pii &py = pos[y];
pii p;
p.ff = px.ff - py.ff;
p.ss = px.ss - py.ss;
return (p.ff * p.ss == 0) && (abs(p.ff + p.ss) == 1);
}
bool can(int i1, int i2, int j1, int j2) {
vector<int> v;
for(int i = i1; i <= i2; i++)
for(int j = j1; j <= j2; j++)
v.push_back(a[i][j]);
sort(v.begin(), v.end());
for(int i = 1; i < v.size(); i++)
if(!neighbour(v[i], v[i - 1]))
return 0;
return 1;
}
int main() {
cin >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> a[i][j];
build();
int ans = 0;
for(int s = 0; s < n; s++)
for(int e = s; e < n; e++)
for(int l = 0; l < m; l++)
for(int r = l; r < m; r++) {
if(can(s, e, l, r)) {
ans++;
}
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |