Submission #317080

#TimeUsernameProblemLanguageResultExecution timeMemory
317080casperwangMaxcomp (info1cup18_maxcomp)C++14
100 / 100
306 ms19184 KiB
#include <bits/stdc++.h> #define pb push_back #define pii pair<int,int> #define pip pair<int,pii> #define ff first #define ss second using namespace std; const int MAXN = 1000; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; int mmax = 0; cin >> n >> m; vector <vector<int>> arr(n); for (int i = 0; i < n; i++) { arr[i].resize(m); for (int j = 0; j < m; j++) { cin >> arr[i][j]; mmax = max(mmax, arr[i][j]); } } int ans = -1; vector <vector<int>> vis(n); priority_queue <pip> nxt; for (int j = 0; j < n; j++) { vis[j].resize(m); for (int k = 0; k < m; k++) { vis[j][k] = arr[j][k] - 1; if (arr[j][k] + 100 > mmax) nxt.push(pip(vis[j][k], pii(j, k))); } } vector <int> dx = {0, 1, -1, 0}, dy = {1, 0, 0, -1}; while (nxt.size()) { pip now = nxt.top(); nxt.pop(); if (now.ff != vis[now.ss.ff][now.ss.ss]) continue; if (now.ff <= ans) continue; now.ff--; for (int i = 0; i < 4; i++) { int x = now.ss.ff + dx[i], y = now.ss.ss + dy[i]; if (x < 0 || y < 0 || x >= n || y >= m) continue; ans = max(ans, now.ff - arr[x][y]); if (now.ff > vis[x][y]) { vis[x][y] = now.ff; nxt.push(pip(now.ff, pii(x, y))); } } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...