Submission #1100784

#TimeUsernameProblemLanguageResultExecution timeMemory
1100784Kirill22Maxcomp (info1cup18_maxcomp)C++17
60 / 100
1049 ms79324 KiB
#include "bits/stdc++.h" using namespace std; void solve() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int> (m)), dp(n, vector<int> (m)); set<array<int, 3>> tmp; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; dp[i][j] = a[i][j] - 1; tmp.insert({dp[i][j], i, j}); } } while (!tmp.empty()) { auto [value, x, y] = *tmp.rbegin(); tmp.erase(--tmp.end()); for (auto [x2, y2] : vector<pair<int, int>> {{x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}}) { if (x2 >= 0 && y2 >= 0 && x2 < n && y2 < m && dp[x2][y2] < value - 1) { tmp.erase({dp[x2][y2], x2, y2}); dp[x2][y2] = value - 1; tmp.insert({dp[x2][y2], x2, y2}); } } } int ans = -1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans = max(ans, dp[i][j] - a[i][j]); } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...