Submission #80954

# Submission time Handle Problem Language Result Execution time Memory
80954 2018-10-23T09:03:26 Z farukkastamonuda Maxcomp (info1cup18_maxcomp) C++14
0 / 100
9 ms 8420 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;
int n, m, A[li][li], mn = inf + 5, cev = - inf , mx;
queue< pair<int , pair<int , int> > > q;
int vis[li][li], deg[li][li];
int yon1[6] = {1, - 1, 0, 0};
int yon2[6] = {0, 0, 1, - 1};
pii temp;
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]);
			mn = min(mn, A[i][j]); 
			mx = max(mx, A[i][j]);
		}
	}
	for(int i = 1; i <= n ; i ++){
		for(int j = 1; j <= m; j ++){
			if(A[i][j] == mn){
				q.push(mp(1, mp(i, j)));
			} 
		}
	}
	while(! q.empty()){
		temp = q.front();
		q.pop();
		int val = temp.fi;
		int x = temp.se.fi;
		int y = temp.se.se;
		if(vis[x][y] == 1) continue;
		vis[x][y] = 1;
		deg[x][y] = val;
		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) continue;
			q.push(mp(val + 1, mp(dx, dy)));
		}
	}
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j ++){
			cev = max(cev, A[i][j] - mn - deg[i][j]);
		}
	}
	////
	for(int i = 1; i <= n ; i ++){
		for(int j = 1; j <= m; j ++){
			if(A[i][j] == mx){
				q.push(mp(1, mp(i, j)));
			} 
		}
	}
	memset(vis, 0, sizeof(vis));
	memset(deg, 0, sizeof(deg));
	while(! q.empty()){
		temp = q.front();
		q.pop();
		int val = temp.fi;
		int x = temp.se.fi;
		int y = temp.se.se;
		if(vis[x][y] == 1) continue;
		vis[x][y] = 1;
		deg[x][y] = val;
		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) continue;
			q.push(mp(val + 1, mp(dx, dy)));
		}
	}
	////
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j ++){
			cev = max(cev, mx - A[i][j] - deg[i][j]);
		}
	}
	printf("%d\n", cev);
	return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:19: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:22: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 8 ms 8184 KB Output is correct
2 Correct 8 ms 8184 KB Output is correct
3 Correct 8 ms 8328 KB Output is correct
4 Incorrect 8 ms 8328 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8328 KB Output is correct
2 Correct 8 ms 8328 KB Output is correct
3 Incorrect 9 ms 8420 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8184 KB Output is correct
3 Correct 8 ms 8328 KB Output is correct
4 Incorrect 8 ms 8328 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8184 KB Output is correct
3 Correct 8 ms 8328 KB Output is correct
4 Incorrect 8 ms 8328 KB Output isn't correct
5 Halted 0 ms 0 KB -