Submission #80962

# Submission time Handle Problem Language Result Execution time Memory
80962 2018-10-23T09:38:36 Z farukkastamonuda Maxcomp (info1cup18_maxcomp) C++14
100 / 100
353 ms 25020 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define li 1004
#define mp make_pair
#define pb push_back
#define pii pair<int , pair<int , int> >
using namespace std;
struct node{
	int val, x, y;
};
int n, m, A[li][li], vis[li][li], ans = - inf;
int yon1[6] = {1, - 1, 0, 0};
int yon2[6] = {0, 0, 1, - 1};
queue<node> q;
vector< pair<int , pair<int, int> > > v;
int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j ++){
			scanf("%d", &A[i][j]);
			vis[i][j] = - inf;
			v.pb(mp(A[i][j], mp(i, j)));
		}
	}
	sort(v.begin(), v.end());
	q.push({v.back().fi, v.back().se.fi, v.back().se.se});
	v.pop_back();
	while(! q.empty()){
		node temp = q.front();
		q.pop();
		int val = temp.val;
		int x = temp.x;
		int y = temp.y;
		if(vis[x][y] > val) continue;
		ans = max(ans, val - A[x][y] - 1);
		while((int)v.size() && v.back().fi == val){
			q.push({v.back().fi, v.back().se.fi, v.back().se.se});
			v.pop_back();
		}
		for(int i = 0; i <= 3 ; i ++){
			int dx = x + yon1[i];
			int dy = y + yon2[i];
			if(dx >= 1 && dx <= n && dy >= 1 && dy <= m && val - 1 > vis[dx][dy]){
				vis[dx][dy] = val - 1;
				q.push({val - 1, dx, dy});
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:24:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &A[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 988 KB Output is correct
10 Correct 3 ms 988 KB Output is correct
11 Correct 3 ms 988 KB Output is correct
12 Correct 3 ms 988 KB Output is correct
13 Correct 3 ms 988 KB Output is correct
14 Correct 3 ms 988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 988 KB Output is correct
13 Correct 3 ms 988 KB Output is correct
14 Correct 3 ms 988 KB Output is correct
15 Correct 3 ms 988 KB Output is correct
16 Correct 3 ms 988 KB Output is correct
17 Correct 3 ms 988 KB Output is correct
18 Correct 345 ms 20328 KB Output is correct
19 Correct 345 ms 20340 KB Output is correct
20 Correct 331 ms 20340 KB Output is correct
21 Correct 352 ms 20340 KB Output is correct
22 Correct 340 ms 20340 KB Output is correct
23 Correct 353 ms 20340 KB Output is correct
24 Correct 248 ms 25020 KB Output is correct