답안 #674177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674177 2022-12-23T11:33:59 Z QwertyPi Maxcomp (info1cup18_maxcomp) C++14
60 / 100
500 ms 41272 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
using namespace std;

const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 11;
const int B = 800;

int a[1001][1001];
int mx[1001][1001];
bool vis[1001][1001];

int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};

int n, m; 
bool in(int i, int j){
	return 0 <= i && i < n && 0 <= j && j < m;
}

int32_t main(){
	cin >> n >> m;
	priority_queue<pair<int, int>> pq;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
			mx[i][j] = a[i][j];
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			pq.push({mx[i][j], i * m + j});
		}
	}
	while(pq.size()){
		pair<int, int> t = pq.top(); pq.pop();
		int i = t.se / m, j = t.se % m, val = t.fi;
		if(mx[i][j] != val || vis[i][j]) continue; vis[i][j] = true;

		for(int dir = 0; dir < 4; dir++){
			if(in(i + dx[dir], j + dy[dir]) && mx[i + dx[dir]][j + dy[dir]] < mx[i][j] - 1){
				mx[i + dx[dir]][j + dy[dir]] = mx[i][j] - 1;
				int ni = i + dx[dir], nj = j + dy[dir];
				pq.push({mx[i + dx[dir]][j + dy[dir]], ni * m + nj});
			}
		}
	}
	
	int ans = -1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			ans = max(ans, mx[i][j] - a[i][j] - 1);
		}
	}
	cout << ans << endl;
}

Compilation message

maxcomp.cpp: In function 'int32_t main()':
maxcomp.cpp:41:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   41 |   if(mx[i][j] != val || vis[i][j]) continue; vis[i][j] = true;
      |   ^~
maxcomp.cpp:41:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   41 |   if(mx[i][j] != val || vis[i][j]) continue; vis[i][j] = true;
      |                                              ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 2 ms 920 KB Output is correct
11 Correct 2 ms 832 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Correct 2 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 2 ms 920 KB Output is correct
14 Correct 2 ms 832 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Execution timed out 734 ms 41272 KB Time limit exceeded
19 Halted 0 ms 0 KB -