Submission #317080

# Submission time Handle Problem Language Result Execution time Memory
317080 2020-10-29T02:45:33 Z casperwang Maxcomp (info1cup18_maxcomp) C++14
100 / 100
306 ms 19184 KB
#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 time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 266 ms 8312 KB Output is correct
19 Correct 260 ms 8312 KB Output is correct
20 Correct 300 ms 8056 KB Output is correct
21 Correct 255 ms 8440 KB Output is correct
22 Correct 265 ms 8440 KB Output is correct
23 Correct 258 ms 8312 KB Output is correct
24 Correct 306 ms 19184 KB Output is correct