# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
594171 | piOOE | Sandcastle 2 (JOI22_ho_t5) | C++17 | 5092 ms | 1088 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 <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
bool swapped = false;
if (n > m) {
swapped = true;
swap(n, m);
}
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < (swapped ? m : n); ++i) {
for (int j = 0; j < (swapped ? n : m); ++j) {
if (!swapped) {
cin >> a[i][j];
} else {
cin >> a[j][i];
}
}
}
int x1, y1, x2, y2;
auto MIN = [&](int x, int y) -> bool {
if (x > x1 && a[x - 1][y] < a[x][y]) return false;
if (y > y1 && a[x][y - 1] < a[x][y]) return false;
if (x < x2 && a[x + 1][y] < a[x][y]) return false;
if (y < y2 && a[x][y + 1] < a[x][y]) return false;
return true;
};
auto MAX = [&](int x, int y) -> bool {
if (x > x1 && a[x - 1][y] > a[x][y]) return false;
if (y > y1 && a[x][y - 1] > a[x][y]) return false;
if (x < x2 && a[x + 1][y] > a[x][y]) return false;
if (y < y2 && a[x][y + 1] > a[x][y]) return false;
return true;
};
int ans = 0;
for (x1 = 0; x1 < n; ++x1) {
for (y1 = 0; y1 < m; ++y1) {
for (x2 = x1; x2 < n; ++x2) {
for (y2 = y1; y2 < m; ++y2) {
int cnt = 0;
vector<array<int, 3>> v;
for (int i = x1; i <= x2 && cnt <= 2; ++i) {
for (int j = y1; j <= y2 && cnt <= 2; ++j) {
v.push_back({a[i][j], i, j});
}
}
sort(v.begin(), v.end());
bool ok = true;
for (int i = 1; i < int(v.size()) && ok; ++i) {
ok &= abs(v[i][1] - v[i - 1][1]) + abs(v[i][2] - v[i - 1][2]) <= 1;
}
if (ok) {
ans += 1;
}
}
}
}
}
cout << ans;
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... |