Submission #594180

#TimeUsernameProblemLanguageResultExecution timeMemory
594180piOOESandcastle 2 (JOI22_ho_t5)C++17
15 / 100
5057 ms3616 KiB
#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]; } } } auto adj = [](int x1, int y1, int x2, int y2) { return abs(x1 - x2) + abs(y1 - y2) < 2; }; int ans = 0; for (int x1 = 0; x1 < n; ++x1) { for (int y1 = 0; y1 < m; ++y1) { for (int x2 = x1; x2 < n; ++x2) { set<array<int, 3>> st; int cnt = 0; for (int y2 = y1; y2 < m; ++y2) { for (int x = x1; x <= x2; ++x) { auto it = st.lower_bound({a[x][y2], -1, -1}); if (it != st.end()) { if (it != st.begin()) { cnt -= !adj((*it)[1], (*it)[2], (*prev(it))[1], (*prev(it))[2]); } cnt += !adj(x, y2, (*it)[1], (*it)[2]); } if (it != st.begin()) { it = prev(it); cnt += !adj(x, y2, (*it)[1], (*it)[2]); } st.insert({a[x][y2], x, y2}); } ans += cnt == 0; } } } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...